Skip to content

ROB: Treat a non-numeric text operand as missing in extract_text - #4175

Merged
stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:text-operator-non-numeric-operand
Oct 13, 2026
Merged

stefan6419846 merged 3 commits into
py-pdf:mainfrom
RavSinghChandan:text-operator-non-numeric-operand

Conversation

@RavSinghChandan

Copy link
Copy Markdown
Contributor

A text operator whose operand is not a number, as in

BT /F1 12 Tf (Hello) Tj /X 5 Td (World) Tj ET

made extract_text() raise "ValueError: could not convert string to float: '/X'". The same happened for TL, Tz and Tw (_handle_tl, _handle_tz, _handle_tw and _handle_td all called float() on the raw operand).

These handlers already fall back to a default when the operand is missing. A small helper, _number_operand(), now applies the same fallback when the operand is not a number, so such an operator is treated as having no operand and the text around it is kept: the example extracts as "HelloWorld". This follows how _handle_tm and _handle_cm already handle operands they cannot convert.

The full suite passes locally (1933 tests), and the changed lines are fully covered.

Used Claude Code (Claude Opus 5.5) to help find and patch this and to draft this description; I reviewed and tested the change.

@codecov

codecov Bot commented Oct 9, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.19%. Comparing base (b4c6120) to head (cb2e0f9).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #4175   +/-   ##
=======================================
  Coverage   98.19%   98.19%           
=======================================
  Files          59       59           
  Lines       11700    11704    +4     
  Branches     2198     2199    +1     
=======================================
+ Hits        11489    11493    +4     
  Misses        117      117           
  Partials       94       94           

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

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Renamed it to _get_number_operand.

@RavSinghChandan

Copy link
Copy Markdown
Contributor Author

Yes: the operands here are NumberObject or FloatObject for numbers, which subclass int and float, so it now checks the index and isinstance(..., (int, float)) instead of catching exceptions.

@stefan6419846
stefan6419846 merged commit bfdeff0 into py-pdf:main Oct 13, 2026
21 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