From 116b7cec594f2f4dd9228ccbfe5432be2f067bdb Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 17 Jun 2019 11:59:39 +0200 Subject: [PATCH] Fix #6676: Add missing buffer bound check The string interpolator migth be unclosed at the end of the input --- .../dotty/tools/dotc/parsing/Parsers.scala | 5 +++- compiler/test-resources/repl/i6676 | 25 +++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 compiler/test-resources/repl/i6676 diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 30658114e0b8..ab8a111192f5 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -799,7 +799,10 @@ object Parsers { private def interpolatedString(inPattern: Boolean = false): Tree = atSpan(in.offset) { val segmentBuf = new ListBuffer[Tree] val interpolator = in.name - val isTripleQuoted = in.buf(in.charOffset) == '"' && in.buf(in.charOffset + 1) == '"' + val isTripleQuoted = + in.charOffset + 1 < in.buf.length && + in.buf(in.charOffset) == '"' && + in.buf(in.charOffset + 1) == '"' in.nextToken() def nextSegment(literalOffset: Offset) = segmentBuf += Thicket( diff --git a/compiler/test-resources/repl/i6676 b/compiler/test-resources/repl/i6676 new file mode 100644 index 000000000000..f543c6ae2de3 --- /dev/null +++ b/compiler/test-resources/repl/i6676 @@ -0,0 +1,25 @@ +scala> xml" +1 | xml" + | ^ + | unclosed string literal +1 | xml" + | ^ + | ';' expected, but eof found +scala> xml"" +1 | xml"" + | ^ + |value xml is not a member of StringContext - did you mean StringContext.s? +scala> xml""" +1 | xml""" + | ^ + | unclosed multi-line string literal +1 | xml""" + | ^ + | unclosed multi-line string literal +scala> s" +1 | s" + | ^ + | unclosed string literal +1 | s" + | ^ + | ';' expected, but eof found