Skip to content

Reject Unicode escapes outside literal and comment contents, and ignorable characters in identifiers and keywords. - #1527

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_1010272791
Nov 17, 2026
Merged

copybara-service[bot] merged 1 commit into
masterfrom
test_1010272791

Conversation

@copybara-service

Copy link
Copy Markdown

Reject Unicode escapes outside literal and comment contents, and ignorable characters in identifiers and keywords.

Java translates Unicode escapes before lexing, but the formatter works on the original source text. Escapes such as \u000D can terminate a // comment early and leave the escape in the gap between tokens, and escapes in comment or literal delimiters, or in text block line terminators, make the source text disagree with javac's tokens. This could produce invalid output, crash, or change the value of a text block when it was re-indented. Similarly, javac discards Character.isIdentifierIgnorable characters (such as U+200B) in identifiers and keywords, so their names diverge from the source text.

Reject these inputs with a diagnostic that reports the line and column of the offending escape or character. Unicode escapes in the contents of comments, string literals, character literals, and text blocks are still allowed.

Fixes #372
Fixes #836

…rable characters in identifiers and keywords.

Java translates Unicode escapes before lexing, but the formatter works on the original source text. Escapes such as `\u000D` can terminate a `//` comment early and leave the escape in the gap between tokens, and escapes in comment or literal delimiters, or in text block line terminators, make the source text disagree with javac's tokens. This could produce invalid output, crash, or change the value of a text block when it was re-indented. Similarly, javac discards `Character.isIdentifierIgnorable` characters (such as U+200B) in identifiers and keywords, so their names diverge from the source text.

Reject these inputs with a diagnostic that reports the line and column of the offending escape or character. Unicode escapes in the contents of comments, string literals, character literals, and text blocks are still allowed.

Fixes #372
Fixes #836

PiperOrigin-RevId: 1023620804
@copybara-service
copybara-service Bot merged commit 805b08b into master Nov 17, 2026
3 checks passed
@copybara-service
copybara-service Bot deleted the test_1010272791 branch November 17, 2026 12:29
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.

Formatter crashes on unicode character in comment Formatting failure with zero-width space

1 participant