Skip to content

Conversation

@j-t-1
Copy link
Contributor

@j-t-1 j-t-1 commented Nov 20, 2025

width and height are now treated symmetrically and updated only if they are not provided.

width and height are now treated symmetrically, and updated only if they
are not provided.
@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.16%. Comparing base (ff561f4) to head (02043ba).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3529   +/-   ##
=======================================
  Coverage   97.16%   97.16%           
=======================================
  Files          57       57           
  Lines        9807     9811    +4     
  Branches     1780     1782    +2     
=======================================
+ Hits         9529     9533    +4     
  Misses        167      167           
  Partials      111      111           

☔ View full report in Codecov by Sentry.
📢 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.

Copy link
Collaborator

@stefan6419846 stefan6419846 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Please add a test for an out-of-bounds index.
  • What happens if the width is 0 or negative?
  • Please update the title to reflect what the actual bug was - currently, it is not obvious which logic is meant or what was wrong.

@j-t-1 j-t-1 changed the title BUG: Change logic when adding a page BUG: Change width, height and index branch Nov 20, 2025
@j-t-1 j-t-1 changed the title BUG: Change width, height and index branch BUG: Change if statement when inserting a blank page Nov 20, 2025
@j-t-1
Copy link
Contributor Author

j-t-1 commented Nov 20, 2025

What happens if the width is 0 or negative?
Is the code okay?

PageObject.create_blank_page(self, width, height) gets created with 0 or negative values. Same for height.

If width or height is 0 or negative change use old_page values?

@stefan6419846
Copy link
Collaborator

The specific case from #3337 (comment) is still not tested?

@stefan6419846 stefan6419846 changed the title BUG: Change if statement when inserting a blank page BUG: Avoid accessing invalid page when inserting blank page under some conditions Nov 20, 2025
@j-t-1
Copy link
Contributor Author

j-t-1 commented Nov 20, 2025

Shall I do this?
if (width is None or width <= 0 or height is None or height <= 0) and index < self.get_num_pages():

@j-t-1
Copy link
Contributor Author

j-t-1 commented Nov 20, 2025

The specific case from #3337 (comment) is still not tested?

Add a test for an out-of-bounds index does this I thought.

Have I not done the test correctly?

@stefan6419846
Copy link
Collaborator

If would use if not (width or height) and index <= self.get_num_pages() should be sufficient - negative indices are a common edge case I would not look into and just allow negative list indexing.

Add a test for an out-of-bounds index does this I thought. Have I not done the test correctly?

Have you tested the behavior without your change to the logic? Did it fail? If not, your change most likely does not yet cover the desired case.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Nov 20, 2025

Have you tested the behavior without your change to the logic? Did it fail? If not, your change most likely does not yet cover the desired case.

No. So I do the same check on the old code and make sure it fails?

@stefan6419846
Copy link
Collaborator

Yes. This is the usual way you should assert that your tests are correct.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Nov 20, 2025

If would use if not (width or height) and index <= self.get_num_pages() should be sufficient - negative indices are a common edge case I would not look into and just allow negative list indexing.

Thanks.

Have you tested the behavior without your change to the logic? Did it fail? If not, your change most likely does not yet cover the desired case.

Will do. Is this the only outstanding now?

@stefan6419846
Copy link
Collaborator

Will do. Is this the only outstanding now?

As far as I can currently see, yes. We probably want to cover both variants (setting only width, setting only height), although only one case has previously been broken, but it makes the tests more consistent.

@j-t-1
Copy link
Contributor Author

j-t-1 commented Nov 21, 2025

The old code:

        if width is None or (height is None and index < self.get_num_pages()):
            oldpage = self.pages[index]
            width = oldpage.mediabox.width
            height = oldpage.mediabox.height

Has this error:

        old_page = writer.pages[0]
        page = writer.insert_blank_page(width=10, index=0)
>       assert page.mediabox.width == 10
E       AssertionError: assert 612.0 == 10
E        +  where 612.0 = RectangleObject([0.0, 0.0, 612, 792]).width
E        +    where RectangleObject([0.0, 0.0, 612, 792]) = {'/Type': '/Page', '/Parent': NullObject, '/Resources': {}, '/MediaBox': RectangleObject([0.0, 0.0, 612, 792])}.mediabox

Because the height is None, and thus the width does not get updated. Whereas this PR passes this test.

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.

2 participants