Skip to content

ROB: Do not crash on removing annotations when they are not an array - #4349

Open
RavSinghChandan wants to merge 1 commit into
py-pdf:mainfrom
RavSinghChandan:remove-annotations-not-an-array
Open

RavSinghChandan wants to merge 1 commit into
py-pdf:mainfrom
RavSinghChandan:remove-annotations-not-an-array

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

writer.remove_annotations() and writer.remove_links() raised TypeError: object of type 'NumberObject' has no len() when a page's /Annots is a number, and AttributeError: 'str' object has no attribute 'get_object' when it is a string. An entry of /Annots that is not a dictionary made them fail too.

A /Annots that is not an array now logs "Annotations are not an array: ...", like page.annotations does since #4046, and is left as is. An entry that is not a dictionary has no subtype: it is kept when filtering by subtype and removed with all the annotations.

Added test_remove_annotations__annotations_are_not_an_array and test_remove_annotations__entries_are_not_dictionaries; both fail on main

@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.81%. Comparing base (08065a0) to head (9de0e77).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4349   +/-   ##
=======================================
  Coverage   98.81%   98.81%           
=======================================
  Files          59       59           
  Lines       12123    12128    +5     
  Branches     2305     2306    +1     
=======================================
+ Hits        11979    11984    +5     
  Misses         70       70           
  Partials       74       74           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant