Skip to content

fix: escape non-ASCII characters as \uNNNN in string literals#11

Merged
Brooooooklyn merged 1 commit intomainfrom
02-04-fix_unicode_escape_in_string_literals
Feb 5, 2026
Merged

fix: escape non-ASCII characters as \uNNNN in string literals#11
Brooooooklyn merged 1 commit intomainfrom
02-04-fix_unicode_escape_in_string_literals

Conversation

@Brooooooklyn
Copy link
Copy Markdown
Member

@Brooooooklyn Brooooooklyn commented Feb 5, 2026

Match TypeScript's emitter behavior by escaping all non-ASCII characters (code point > 0x7E) as \uNNNN sequences. Characters above the BMP use UTF-16 surrogate pairs. Uses push_str with hex table lookup instead of fmt::Write.


Note

Medium Risk
Changes emitted JavaScript string literal contents (non-ASCII now always becomes \u escapes), which can affect snapshot tests, output diffs, and any consumers expecting literal UTF-8 in generated code; logic is localized but touches core emission paths.

Overview
Updates escape_string in the Angular compiler JS emitter to always escape non-ASCII characters (and ASCII control chars) as \uNNNN, emitting UTF-16 surrogate pairs for code points above the BMP to match TypeScript’s string-literal printer.

Adds a small helper (push_unicode_escape) to build escapes without formatting, expands unit coverage around surrogate pairs and non-ASCII cases, and updates integration assertions so compiled templates with HTML entities (e.g. ×,  ) now produce escaped sequences instead of literal Unicode characters.

Written by Cursor Bugbot for commit 8d880a6. This will update automatically on new commits. Configure here.

Match TypeScript's emitter behavior by escaping all non-ASCII characters
(code point > 0x7E) as \uNNNN sequences. Characters above the BMP use
UTF-16 surrogate pairs. Uses push_str with hex table lookup instead of
fmt::Write.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@Brooooooklyn Brooooooklyn merged commit 9d38e9c into main Feb 5, 2026
3 checks passed
@Brooooooklyn Brooooooklyn deleted the 02-04-fix_unicode_escape_in_string_literals branch February 5, 2026 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant