Skip to content

Don't write numbers in exponential notation when saving a pdf - #21683

Merged
calixteman merged 1 commit into
mozilla:masterfrom
calixteman:fix/quad-regex-writer
Aug 3, 2026
Merged

Don't write numbers in exponential notation when saving a pdf#21683
calixteman merged 1 commit into
mozilla:masterfrom
calixteman:fix/quad-regex-writer

Conversation

@calixteman

@calixteman calixteman commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

toFixed(10) switches to the exponential notation from 1e21 on, which isn't valid PDF syntax, and removing the trailing zeros then dropped a digit of the exponent: 1e30 was written "1e+3" and 1e100 "1e+1". Such a number, necessarily an integer, is now written with all its digits.
The trailing zeros are removed with a backward scan, since toFixed(10) always produces exactly 10 decimals. Below the 1e21 limit its output is at most 33 characters long, so the previous $-anchored regex wasn't a performance issue.

@calixteman calixteman added the core label Aug 1, 2026
@codecov-commenter

codecov-commenter commented Aug 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.97%. Comparing base (d0779c4) to head (5375bff).
⚠️ Report is 10 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21683      +/-   ##
==========================================
- Coverage   90.00%   89.97%   -0.04%     
==========================================
  Files         263      263              
  Lines       66861    66968     +107     
==========================================
+ Hits        60178    60252      +74     
- Misses       6683     6716      +33     
Flag Coverage Δ
browsertest 66.54% <90.00%> (+0.02%) ⬆️
fonttest 9.04% <ø> (ø)
unittest 57.87% <100.00%> (+0.03%) ⬆️
unittestcli 56.58% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment thread src/core/writer.js Outdated
Comment thread src/core/writer.js Outdated
`toFixed(10)` switches to the exponential notation from 1e21 on, which isn't
valid PDF syntax, and removing the trailing zeros then dropped a digit of the
exponent: 1e30 was written "1e+3" and 1e100 "1e+1". Such a number, necessarily
an integer, is now written with all its digits.

The trailing zeros are removed with a backward scan, since `toFixed(10)` always
produces exactly 10 decimals. Below the 1e21 limit its output is at most 33
characters long, so the previous `$`-anchored regex wasn't a performance issue.
@calixteman calixteman changed the title Bound the trailing zeros when writing a number Don't write numbers in exponential notation when saving a pdf Aug 3, 2026
@calixteman
calixteman merged commit ba7bf7b into mozilla:master Aug 3, 2026
19 of 21 checks passed
@calixteman
calixteman deleted the fix/quad-regex-writer branch August 3, 2026 15:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants