Skip to content

fix: reject numeric character references with trailing non-digit characters#45

Merged
rgrove merged 1 commit into
rgrove:mainfrom
spokodev:fix/reject-malformed-numeric-char-refs
Jul 11, 2026
Merged

fix: reject numeric character references with trailing non-digit characters#45
rgrove merged 1 commit into
rgrove:mainfrom
spokodev:fix/reject-malformed-numeric-char-refs

Conversation

@spokodev

@spokodev spokodev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

parseXml('<a>&#65a;</a>') returns the text A instead of throwing. A numeric character reference is validated with parseInt(), which stops at the first character that isn't a valid digit and returns whatever it parsed up to that point. So a malformed reference whose trailing Name characters aren't digits is silently accepted and resolved to its leading numeric portion:

  • &#65a; -> A
  • &#48f; -> 0
  • &#x41g; -> A
  • &#65z; -> A

Per CharRef a character reference is '&#' [0-9]+ ';' or '&#x' [0-9a-fA-F]+ ';', so each of these is a well-formedness error and should be rejected.

Fix validates the reference digits before resolving the code point. Valid decimal, hex (including uppercase and supplementary code points), and predefined entities are unaffected.

Adds a regression test.

…acters

A numeric character reference must consist solely of digits (`&#[0-9]+;`
or `&#x[0-9a-fA-F]+;`), but the reference was validated with parseInt(),
which silently stops at the first invalid digit. As a result malformed
references such as `&#65a;`, `&#48f;`, and `&#x41g;` were accepted and
resolved to their leading numeric portion (`A`, `0`, `A`) instead of being
rejected as a well-formedness error.

Validate the reference digits before resolving the code point.

@rgrove rgrove left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks!

@rgrove rgrove merged commit 48dd065 into rgrove:main Jul 11, 2026
4 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