Repository navigation
Reject Unicode escapes outside literal and comment contents, and ignorable characters in identifiers and keywords. - #1527
Merged
Conversation
…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
Bot
force-pushed
the
test_1010272791
branch
from
November 17, 2026 12:29
1e3251d to
805b08b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
\u000Dcan 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 discardsCharacter.isIdentifierIgnorablecharacters (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