From d789698f45023a19b4ae4d5802d64690268b74bb Mon Sep 17 00:00:00 2001 From: Geoffrey Washburn Date: Tue, 12 Aug 2008 11:04:01 +0000 Subject: Correction to Sean's decoding fix. Added a simple test for the unicode decoding stuff. --- src/compiler/scala/tools/nsc/util/NameTransformer.scala | 9 +++++---- test/files/pos/unicode-decode.scala | 9 +++++++++ 2 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 test/files/pos/unicode-decode.scala diff --git a/src/compiler/scala/tools/nsc/util/NameTransformer.scala b/src/compiler/scala/tools/nsc/util/NameTransformer.scala index 855b2d563d..f57334e362 100644 --- a/src/compiler/scala/tools/nsc/util/NameTransformer.scala +++ b/src/compiler/scala/tools/nsc/util/NameTransformer.scala @@ -109,11 +109,12 @@ object NameTransformer { } /* Handle the decoding of Unicode glyphs that are * not valid Java/JVM identifiers */ - } else if (ch1 == 'u' && - (Character.isDigit(ch2)) || - ('A' <= ch2 && ch2 <= 'F')) { + } else if ((len - i) >= 6 && // Check that there are enough characters left + ch1 == 'u' && + (Character.isDigit(ch2)) || + ('A' <= ch2 && ch2 <= 'F')) { /* Skip past "$u", next four should be hexadecimal */ - val hex = name.substring(i+2, if (i+6 <= len) i+6 else len) + val hex = name.substring(i+2, i+6) try { val str = Integer.parseInt(hex, 16).toChar if (buf eq null) { diff --git a/test/files/pos/unicode-decode.scala b/test/files/pos/unicode-decode.scala new file mode 100644 index 0000000000..9818ed64a4 --- /dev/null +++ b/test/files/pos/unicode-decode.scala @@ -0,0 +1,9 @@ +object Test { + + val ↑ = 3 + val x$u20A2 = 4 + val y$ub = 5 + val y$u0A = 6 + val z$up = 2 + +} -- cgit v1.2.3