Skip to content

Commit

Permalink
Fix a crash lexing text blocks
Browse files Browse the repository at this point in the history
Follow-up to 05fee69

PiperOrigin-RevId: 577853770
  • Loading branch information
cushon authored and Javac Team committed Oct 30, 2023
1 parent 5b357d0 commit ae935f4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions java/com/google/turbine/parse/StreamLexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,9 @@ private Token textBlock() {
// that \" escapes don't count towards the closing delimiter of the text block.
sb.appendCodePoint(ch);
eat();
if (ch == ASCII_SUB && reader.done()) {
return Token.EOF;
}
sb.appendCodePoint(ch);
eat();
continue;
Expand Down
9 changes: 9 additions & 0 deletions javatests/com/google/turbine/parse/LexerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,13 @@ public void textBlockNewlineEscapes() throws Exception {
lexerComparisonTest(input);
assertThat(lex(input)).containsExactly("STRING_LITERAL(hellohellohello)", "EOF");
}

// Check for EOF when skipping over escapes in text blocks
@Test
public void textBlockEOF() {
String input = "\"\"\"\n\\";
Lexer lexer = new StreamLexer(new UnicodeEscapePreprocessor(new SourceFile(null, input)));
assertThat(lexer.next()).isEqualTo(Token.EOF);
assertThat(lexer.stringValue()).isEqualTo("\\");
}
}

0 comments on commit ae935f4

Please sign in to comment.