Skip to content

Commit 9604ec6

Browse files
JeanMechethePunderWoman
authored andcommitted
refactor(compiler): prevent object methods being recognised as entities (angular#58100)
With this commit object methods (like `valueOf`, `toString` are not considered as valid entities anymore. PR Close angular#58100
1 parent 88a2c92 commit 9604ec6

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

packages/compiler/src/ml_parser/lexer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ class _Tokenizer {
672672
} else {
673673
const name = this._cursor.getChars(nameStart);
674674
this._cursor.advance();
675-
const char = NAMED_ENTITIES[name];
675+
const char = NAMED_ENTITIES.hasOwnProperty(name) && NAMED_ENTITIES[name];
676676
if (!char) {
677677
throw this._createError(_unknownEntityErrorMsg(name), this._cursor.getSpan(start));
678678
}

packages/compiler/test/ml_parser/lexer_spec.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,6 +2204,16 @@ describe('HtmlLexer', () => {
22042204
[TokenType.ENCODED_ENTITY, 'Unexpected character "EOF"', '0:6'],
22052205
]);
22062206
});
2207+
2208+
it('should not parse js object methods', () => {
2209+
expect(tokenizeAndHumanizeErrors('&valueOf;')).toEqual([
2210+
[
2211+
TokenType.ENCODED_ENTITY,
2212+
'Unknown entity "valueOf" - use the "&#<decimal>;" or "&#x<hex>;" syntax',
2213+
'0:0',
2214+
],
2215+
]);
2216+
});
22072217
});
22082218

22092219
describe('regular text', () => {

0 commit comments

Comments
 (0)