From f4ff84db34fa87288c346af1b5b033f5ce8c7013 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 1 Aug 2014 16:12:53 -0400 Subject: [PATCH 1/2] Fixes #1375 - Check for empty filenames. Starting sbt in root isn't a great idea, but it shouldn't break. --- main/src/main/scala/sbt/Project.scala | 5 ++++- main/src/test/scala/ProjectSpec.scala | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 main/src/test/scala/ProjectSpec.scala diff --git a/main/src/main/scala/sbt/Project.scala b/main/src/main/scala/sbt/Project.scala index d9b3a8ee9..7753836ad 100755 --- a/main/src/main/scala/sbt/Project.scala +++ b/main/src/main/scala/sbt/Project.scala @@ -242,7 +242,10 @@ object Project extends ProjectExtra { def normalizeProjectID(id: String): Either[String, String] = { val attempt = normalizeBase(id) - val refined = if (!validProjectIDStart(attempt.substring(0, 1))) "root-" + attempt else attempt + val refined = + if (attempt.length < 1) "root" + else if (!validProjectIDStart(attempt.substring(0, 1))) "root-" + attempt + else attempt validProjectID(refined).toLeft(refined) } private[this] def normalizeBase(s: String) = s.toLowerCase(Locale.ENGLISH).replaceAll("""\W+""", "-") diff --git a/main/src/test/scala/ProjectSpec.scala b/main/src/test/scala/ProjectSpec.scala new file mode 100644 index 000000000..5dd9d6511 --- /dev/null +++ b/main/src/test/scala/ProjectSpec.scala @@ -0,0 +1,18 @@ +package sbt + +import org.specs2.Specification + +class ProjectSpec extends Specification { + def is = s2""" + + This is a specification to check utility methods on the Project object + + Project should + normalize projectIDs if they are empty ${normalizeEmptyFileName} + + """ + + def emptyFilename = "" + + def normalizeEmptyFileName = Project.normalizeProjectID(emptyFilename) must equalTo(Right("root")) +} \ No newline at end of file From 5150339a0a2cf861e20f3866e03a23035eee8891 Mon Sep 17 00:00:00 2001 From: Josh Suereth Date: Fri, 1 Aug 2014 17:20:03 -0400 Subject: [PATCH 2/2] Add notes so we have a merge conflict. Conflicts: notes/0.13.6.md --- notes/0.13.6.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/notes/0.13.6.md b/notes/0.13.6.md index c542ee36c..a35f51ff1 100644 --- a/notes/0.13.6.md +++ b/notes/0.13.6.md @@ -35,6 +35,7 @@ [1477]: https://github.com/sbt/sbt/pull/1477 [1486]: https://github.com/sbt/sbt/pull/1486 [1487]: https://github.com/sbt/sbt/pull/1487 + [1488]: https://github.com/sbt/sbt/pull/1488 [@dansanduleac]: https://github.com/dansanduleac [@2m]: https://github.com/2m [@pvlugter]: https://github.com/pvlugter @@ -80,6 +81,7 @@ - Works around "Not a simple type" breaking `-Xfatal-warnings`. [#1477][1477] by [@puffnfresh][@puffnfresh] - Fixes sLog usage in tandem with the `set` comamnd [#1486][1486] [@jsuereth][@jsuereth] - Test suites with whitespace will have prettier filenames [#1487][1487] [@jsuereth][@jsuereth] +- sbt no longer crashes when run in root directory [#1488][1488] by [@jsuereth][@jsuereth] ### enablePlugins/disablePlugins