Skip to content

fix(compiler): length-prefix string literals and quoted map keys in ConstantPool keys - #71932

Open
JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:fix/constant-pool-key-escaping
Open

JeanMeche wants to merge 1 commit into
angular:mainfrom
JeanMeche:fix/constant-pool-key-escaping

Conversation

@JeanMeche

@JeanMeche JeanMeche commented Nov 10, 2026 •

Copy link
Copy Markdown
Member

Previously, GenericKeyFn.keyOf() wrapped string literals and quoted object literal keys in double quotes without length-prefixing or escaping. As a result, distinct array or object literals extracted during the template compiler's pure function optimization phase (generatePureLiteralStructures / extractPureFunctions -> PureFunctionConstant in ConstantPool) such as ["a", "b"] vs ['a","b'] or {"a": 1, "b": 2} vs {'a":1,"b': 2} produced identical constant pool keys (["a","b"] and {"a":1,"b":2}) and erroneously shared the same constant factory.

This change prefixes string literals and quoted object literal keys with their length ("${value.length}:${value}") in GenericKeyFn.keyOf(). This guarantees a prefix-free (uniquely decodable) key encoding with O(1) overhead and avoids scanning or escaping characters via JSON.stringify().

Fixes #71914

@angular-robot angular-robot Bot added the area: compiler Issues related to `ngc`, Angular's template compiler label Nov 10, 2026
@ngbot ngbot Bot added this to the Backlog milestone Nov 10, 2026
@JeanMeche
JeanMeche force-pushed the fix/constant-pool-key-escaping branch from b94b407 to e62232d Compare November 10, 2026 21:06
@JeanMeche JeanMeche changed the title fix(compiler): escape string literals and quoted map keys in ConstantPool keys fix(compiler): length-prefix string literals and quoted map keys in ConstantPool keys Nov 10, 2026
…onstantPool keys

Previously, GenericKeyFn.keyOf() wrapped string literals and quoted object literal keys in double quotes without length-prefixing or escaping. As a result, distinct array or object literals extracted during the template compiler's pure function optimization phase (such as ['a', 'b'] and ['a","b'], or {'a': 1, 'b': 2} and {'a":1,"b': 2}) produced identical constant pool keys and erroneously shared the same constant factory.

Prefix string literals and quoted object literal keys with their length ("<length>:<value>") in GenericKeyFn.keyOf() so embedded quotes and delimiters cannot cause key collisions without needing to scan or escape the string.

Fixes angular#71914
@JeanMeche
JeanMeche force-pushed the fix/constant-pool-key-escaping branch from e62232d to f006b9a Compare November 10, 2026 21:37
@JeanMeche
JeanMeche marked this pull request as ready for review November 10, 2026 21:38
@JeanMeche
JeanMeche requested a review from crisbeto November 10, 2026 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: compiler Issues related to `ngc`, Angular's template compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

compiler: distinct array literals can share a constant pool key and produce incorrect results

1 participant