Skip to content

BUG: Reject a non-positive number when building a Roman numeral - #4005

Merged
stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:reject-non-positive-roman-numeral
Aug 25, 2026
Merged

stefan6419846 merged 1 commit into
py-pdf:mainfrom
RavSinghChandan:reject-non-positive-roman-numeral

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

number2uppercase_roman_numeral(-1) returns 'CMXCIX' and 0 returns an empty string:

>>> number2uppercase_roman_numeral(-1)
'CMXCIX'
>>> number2uppercase_roman_numeral(0)
''

The loop subtracts each value it emits and stops once the remainder reaches zero, which a negative input satisfies after a single pass over the table.

number2uppercase_letter and number2lowercase_letter beside it already refuse a non-positive number with the same message, so this brings the four numbering styles in line.

index2label already catches ValueError from the mapping function and falls back to the page position, so a file carrying /St 0 now logs "Ignoring malformed page label entry" rather than labelling a page CMXCIX.

Reverting the change fails the three new tests

number2uppercase_roman_numeral(-1) returned 'CMXCIX' and 0 returned an empty
string: the loop subtracts each value it emits and stops once the remainder
reaches zero, which a negative input satisfies after one pass over the table.

number2uppercase_letter and number2lowercase_letter beside it already refuse a
non-positive number, and index2label catches ValueError from the mapping
function to fall back to the page position, so a file with /St 0 now reports a
malformed entry rather than a nonsense numeral.
@codecov

codecov Bot commented Aug 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.98%. Comparing base (799f2d8) to head (6a428e1).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4005   +/-   ##
=======================================
  Coverage   97.98%   97.98%           
=======================================
  Files          57       57           
  Lines       11106    11108    +2     
  Branches     2080     2081    +1     
=======================================
+ Hits        10882    10884    +2     
  Misses        125      125           
  Partials       99       99           

☔ 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.

@stefan6419846
stefan6419846 merged commit bc1a49f into py-pdf:main Aug 25, 2026
30 of 34 checks passed
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