commit | 9e5f9627cde8caa7099d267e8b9de9d62f380aa9 | [log] [tgz] |
---|---|---|
author | cushon <cushon@google.com> | Tue Nov 01 11:02:51 2016 -0700 |
committer | Liam Miller-Cushon <cushon@google.com> | Tue Nov 01 15:46:31 2016 -0700 |
tree | 30ec644a9d3c183b497d68fa37180c821f6cac7c | |
parent | 537ed3ffa963be3f540704a90c73533de30db718 [diff] |
Fix unicode escape handling bug Consider escaped and unescaped backslashes when tracking the number of leading backslashes. MOE_MIGRATED_REVID=137844590
diff --git a/java/com/google/turbine/parse/UnicodeEscapePreprocessor.java b/java/com/google/turbine/parse/UnicodeEscapePreprocessor.java index 2bbd897..a8b5880 100644 --- a/java/com/google/turbine/parse/UnicodeEscapePreprocessor.java +++ b/java/com/google/turbine/parse/UnicodeEscapePreprocessor.java
@@ -82,7 +82,7 @@ eat(); acc |= (char) (hexDigit(ch) & 0xff); ch = acc; - evenLeadingSlashes = true; + evenLeadingSlashes = ch != '\\'; } /** Consumes a hex digit. */
diff --git a/javatests/com/google/turbine/parse/UnicodeEscapePreprocessorTest.java b/javatests/com/google/turbine/parse/UnicodeEscapePreprocessorTest.java index ad88692..2637091 100644 --- a/javatests/com/google/turbine/parse/UnicodeEscapePreprocessorTest.java +++ b/javatests/com/google/turbine/parse/UnicodeEscapePreprocessorTest.java
@@ -69,6 +69,11 @@ } } + @Test + public void escapeEscape() { + assertThat(readAll("\\u005C\\\\u005C")).containsExactly('\\', '\\', '\\'); + } + private List<Character> readAll(String input) { UnicodeEscapePreprocessor reader = new UnicodeEscapePreprocessor(new SourceFile(null, input)); List<Character> result = new ArrayList<>();