fix(compiler): parse named HTML entities containing digits#67229
Open
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
Open
fix(compiler): parse named HTML entities containing digits#67229yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
yogeshwaran-c wants to merge 1 commit intoangular:mainfrom
Conversation
The lexer's isNamedEntityEnd function stopped scanning entity names when encountering a digit character, causing 24 valid HTML named entities with digits in their names (e.g. ¹, ½, ▓) to be treated as plain text instead of decoded to their corresponding Unicode characters. Fixes angular#51323
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.
What kind of change does this PR introduce?
Bug fix
What is the current behavior?
Named HTML entities containing digits (e.g.
¹,½,▓,∴) are not processed correctly by the Angular template compiler. Instead of being decoded to their corresponding Unicode characters, they are output as escaped text (e.g.¹instead of¹).This affects all 24 valid HTML named entities that contain digits in their names:
blk12,blk14,blk34,emsp13,emsp14,frac12,frac13,frac14,frac15,frac16,frac18,frac23,frac25,frac34,frac35,frac38,frac45,frac56,frac58,frac78,sup1,sup2,sup3,there4.Closes #51323
What is the new behavior?
The lexer's
isNamedEntityEndfunction now accepts digits as valid characters within named entity references, allowing all standard HTML named entities to be parsed and decoded correctly.Additional context
The root cause was in the
isNamedEntityEndfunction inpackages/compiler/src/ml_parser/lexer.ts. This function determines when to stop scanning a named entity reference. It used!chars.isAsciiLetter(code)as its termination condition, which meant any digit would immediately end the entity name scan. For an entity like¹, the scanner would stop atsup(before the1), never reach the semicolon, and fall back to treating the&as plain text.The fix adds
chars.isDigit(code)to the valid character check, so entity names likesup1andfrac12are fully scanned.The entity lookup table in
entities.tsalready contained all 24 entities — only the lexer scanning logic needed to be updated.