Fixes #1375 - Check for empty filenames.

Starting sbt in root isn't a great idea, but it shouldn't break.
This commit is contained in:
Josh Suereth 2014-08-01 16:12:53 -04:00 committed by Eugene Yokota
parent 550a7f8e96
commit f4ff84db34
2 changed files with 22 additions and 1 deletions

View File

@ -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+""", "-")

View File

@ -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"))
}