Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion packages/compiler/src/ml_parser/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1431,7 +1431,12 @@ function isDigitEntityEnd(code: number): boolean {
}

function isNamedEntityEnd(code: number): boolean {
return code === chars.$SEMICOLON || code === chars.$EOF || !chars.isAsciiLetter(code);
// Named entities may contain digits (e.g. ¹, ½, ▓).
return (
code === chars.$SEMICOLON ||
code === chars.$EOF ||
!(chars.isAsciiLetter(code) || chars.isDigit(code))
);
}

function isExpansionCaseStart(peek: number): boolean {
Expand Down
11 changes: 11 additions & 0 deletions packages/compiler/test/ml_parser/html_parser_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,17 @@ describe('HtmlParser', () => {
]);
});

it('should parse named HTML entities containing digits', () => {
expect(humanizeDom(parser.parse('<div>&sup1;</div>', 'TestComp'))).toEqual([
[html.Element, 'div', 0],
[html.Text, '\u00B9', 1, [''], ['\u00B9', '&sup1;'], ['']],
]);
expect(humanizeDom(parser.parse('<div>&frac12;</div>', 'TestComp'))).toEqual([
[html.Element, 'div', 0],
[html.Text, '\u00BD', 1, [''], ['\u00BD', '&frac12;'], ['']],
]);
});

it('should normalize line endings within CDATA', () => {
const parsed = parser.parse('<![CDATA[ line 1 \r\n line 2 ]]>', 'TestComp');
expect(humanizeDom(parsed)).toEqual([
Expand Down
21 changes: 21 additions & 0 deletions packages/compiler/test/ml_parser/lexer_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2094,6 +2094,27 @@ describe('HtmlLexer', () => {
]);
});

it('should parse named entities containing digits', () => {
expect(tokenizeAndHumanizeParts('&sup1;')).toEqual([
[TokenType.TEXT, ''],
[TokenType.ENCODED_ENTITY, '\u00B9', '&sup1;'],
[TokenType.TEXT, ''],
[TokenType.EOF],
]);
expect(tokenizeAndHumanizeParts('&frac12;')).toEqual([
[TokenType.TEXT, ''],
[TokenType.ENCODED_ENTITY, '\u00BD', '&frac12;'],
[TokenType.TEXT, ''],
[TokenType.EOF],
]);
expect(tokenizeAndHumanizeParts('&blk34;')).toEqual([
[TokenType.TEXT, ''],
[TokenType.ENCODED_ENTITY, '\u2593', '&blk34;'],
[TokenType.TEXT, ''],
[TokenType.EOF],
]);
});

it('should parse hexadecimal entities', () => {
expect(tokenizeAndHumanizeParts('&#x41;&#X41;')).toEqual([
[TokenType.TEXT, ''],
Expand Down