fix: reject numeric character references with trailing non-digit characters#45
Merged
rgrove merged 1 commit intoJul 11, 2026
Merged
Conversation
…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 `Aa;`, `0f;`, and `Ag;` 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
parseXml('<a>Aa;</a>')returns the textAinstead of throwing. A numeric character reference is validated withparseInt(), 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 trailingNamecharacters aren't digits is silently accepted and resolved to its leading numeric portion:Aa;->A0f;->0Ag;->AAz;->APer
CharRefa 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.