Skip to content

fix(html2json): preserve numeric-looking string codes verbatim - #9

Merged
kozmaadrian merged 1 commit into
mainfrom
fix/html2json-lossy-number-coercion
Jun 23, 2026
Merged

kozmaadrian merged 1 commit into
mainfrom
fix/html2json-lossy-number-coercion

Conversation

@kozmaadrian

Copy link
Copy Markdown
Collaborator

Problem

String values that look like numbers were silently coerced to numbers during HTML→JSON conversion, corrupting opaque codes. E.g. "710E-3" (valid scientific notation) became 0.71.

Cause

getNumber() used Number(text), which accepts forms that don't round-trip:

  • scientific notation — 710E-3 → 0.71
  • hex — 0xFF → 255
  • leading zeros — 007 → 7
  • precision-losing big integers

Fix

Only coerce when the text is already the number's canonical form (String(num) === text). Anything else is kept as a string. Genuine numbers like 25, 99.99, -5 are unaffected.

Tests

Added regression tests covering non-canonical numeric strings, numeric-looking list items, and canonical numbers (incl. negatives).

Checklist:

  • I have signed the Adobe Open Source CLA.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@kozmaadrian
kozmaadrian requested a review from mhaack June 22, 2026 21:07
@kozmaadrian
kozmaadrian merged commit 789bcf4 into main Jun 23, 2026
5 checks passed
@kozmaadrian
kozmaadrian deleted the fix/html2json-lossy-number-coercion branch June 23, 2026 07:37
github-actions Bot pushed a commit that referenced this pull request Jun 23, 2026
## [0.1.2](v0.1.1...v0.1.2) (2026-06-23)

### Bug Fixes

* **html2json:** preserve numeric-looking string codes verbatim ([#9](#9)) ([789bcf4](789bcf4))
@github-actions

Copy link
Copy Markdown

🎉 This PR is included in version 0.1.2 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants