You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Reject Unicode escapes outside literals/comments and ignorable characters, with a clear diagnostic #244
google-java-format#1527 (merged, fixes google-java-format#372 and google-java-format#836) hardens JavaInput. Javac translates Unicode escapes before lexing but the formatter works on the original text, so an escape such as a carriage return inside a // comment, an escape in a comment or literal delimiter, or one in a text block line terminator can make the output invalid, crash the formatter, or change a text block's value. Likewise javac drops identifier-ignorable characters (for example a zero-width space) in names and keywords, so token text diverges from the source. Upstream now rejects these inputs up front with a diagnostic giving line and column; escapes inside comment, string, char and text block contents stay allowed.
Why it matters to us: our JavaInput has only a narrow guard (it throws "Unicode escapes not allowed in whitespace or multi-character operators" in buildToks) and no check for ignorable characters, so the same inputs probably still give the cryptic "expected token ... generated ..." failure, or silently corrupt a text block. The diff is large (about 130 added lines in JavaInput.java, changes in JavacTokens.java, 190 lines of new DiagnosticTest cases), so it needs to be adapted to our package layout rather than applied cleanly.
Affected files: open-java-format/src/main/java/com/palantir/javaformat/java/JavaInput.java, our JavacTokens equivalent, and the diagnostic tests.
Examples: not available - the change turns failures into rejection diagnostics; it does not change formatted output for accepted input.
Suggested action: investigate by reproducing both upstream issues against our build (a comment containing an escaped carriage return; a zero-width space inside an identifier), then port the check and its tests.
Filed from an upstream-watch ticket after manual review.
Activity