Permalink
Browse files

SI-6194, repl crash.

Always a bad idea to use replaceAll on unknown strings,
as we saw here when windows classpaths arrived containing
escape-requiring backslashes.
  • Loading branch information...
1 parent 1284c3c commit ac61e341216c2c61e29c74a8c3c27e915d479925 @paulp paulp committed Dec 27, 2012
Showing with 15 additions and 2 deletions.
  1. +6 −2 src/compiler/scala/tools/nsc/util/ClassPath.scala
  2. +1 −0 test/files/run/t6194.check
  3. +8 −0 test/files/run/t6194.scala
@@ -15,6 +15,7 @@ import scala.reflect.ClassTag
import Jar.isJarOrZip
import File.pathSeparator
import java.net.MalformedURLException
+import java.util.regex.PatternSyntaxException
/** <p>
* This module provides star expansion of '-classpath' option arguments, behaves the same as
@@ -39,8 +40,11 @@ object ClassPath {
if (pattern == "*") lsDir(Directory("."))
else if (pattern endsWith wildSuffix) lsDir(Directory(pattern dropRight 2))
else if (pattern contains '*') {
- val regexp = ("^%s$" format pattern.replaceAll("""\*""", """.*""")).r
- lsDir(Directory(pattern).parent, regexp findFirstIn _ isDefined)
+ try {
+ val regexp = ("^" + pattern.replaceAllLiterally("""\*""", """.*""") + "$").r
+ lsDir(Directory(pattern).parent, regexp findFirstIn _ isDefined)
+ }
+ catch { case _: PatternSyntaxException => List(pattern) }
}
else List(pattern)
}
@@ -0,0 +1 @@
+C:\FooBar\Java\includes\*.jar
@@ -0,0 +1,8 @@
+import scala.tools.nsc.util._
+
+object Test {
+ def main(args: Array[String]): Unit = {
+ val cp = ClassPath.expandPath("""C:\FooBar\Java\includes\*.jar""") mkString java.io.File.pathSeparator
+ println(cp)
+ }
+}

0 comments on commit ac61e34

Please sign in to comment.