summaryrefslogtreecommitdiff
path: root/src/library
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2012-12-06 11:56:40 -0800
committerAdriaan Moors <adriaan.moors@typesafe.com>2012-12-06 11:56:40 -0800
commit58969850a0991a72c360433540943eae4b10dc6b (patch)
treef52d371ff5459f08edb6794e57f0a3dca5bd2ef0 /src/library
parentf4acacd1d8e1b26742f188579c782f6f150d6c89 (diff)
parentd483ec3a5d4688577921611b30508ca6403be858 (diff)
downloadscala-58969850a0991a72c360433540943eae4b10dc6b.tar.gz
scala-58969850a0991a72c360433540943eae4b10dc6b.tar.bz2
scala-58969850a0991a72c360433540943eae4b10dc6b.zip
Merge pull request #1690 from retronym/ticket/6631
SI-6631 Handle invalid escapes in string interpolators
Diffstat (limited to 'src/library')
-rw-r--r--src/library/scala/StringContext.scala13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/library/scala/StringContext.scala b/src/library/scala/StringContext.scala
index 8be0cb1619..1b5fd6c8d3 100644
--- a/src/library/scala/StringContext.scala
+++ b/src/library/scala/StringContext.scala
@@ -100,8 +100,8 @@ case class StringContext(parts: String*) {
* ''Note:'' Even when using the raw interpolator, Scala will preprocess unicode escapes.
* For example:
* {{{
- * scala> raw"\u0123"
- * res0: String = ģ
+ * scala> raw"\u005cu0025"
+ * res0: String = #
* }}}
*
* @param `args` The arguments to be inserted into the resulting string.
@@ -191,7 +191,7 @@ object StringContext {
var cur = 0
var idx = 0
def output(ch: Char) = {
- bldr append str.substring (start, cur)
+ bldr.append(str, start, cur)
bldr append ch
start = idx
}
@@ -199,14 +199,15 @@ object StringContext {
cur = idx
if (str(idx) == '\\') {
idx += 1
+ if (idx >= len) throw new InvalidEscapeException(str, cur)
if ('0' <= str(idx) && str(idx) <= '7') {
val leadch = str(idx)
var oct = leadch - '0'
idx += 1
- if ('0' <= str(idx) && str(idx) <= '7') {
+ if (idx < len && '0' <= str(idx) && str(idx) <= '7') {
oct = oct * 8 + str(idx) - '0'
idx += 1
- if (leadch <= '3' && '0' <= str(idx) && str(idx) <= '7') {
+ if (idx < len && leadch <= '3' && '0' <= str(idx) && str(idx) <= '7') {
oct = oct * 8 + str(idx) - '0'
idx += 1
}
@@ -234,6 +235,6 @@ object StringContext {
}
}
if (start == 0) str
- else (bldr append str.substring(start, idx)).toString
+ else bldr.append(str, start, idx).toString
}
}