Don't add extra quotation marks in scripted commands

Scripted automatically adding quotation marks when an argument contains
spaces breaks arguments that already were wrapped in quotations. The
scripted test should be responsible for its own escaping. Since this is
part of scripted-sbt-redux, we don't have to worry about downstream
builds relying on the old escaping behavior.
This commit is contained in:
Ethan Atkins 2020-01-11 11:26:37 -08:00
parent 639b812a01
commit b9231a49cc
3 changed files with 13 additions and 9 deletions

View File

@ -2,8 +2,16 @@ val scalatest = "org.scalatest" %% "scalatest" % "3.0.5"
ThisBuild / scalaVersion := "2.12.10"
val foo = settingKey[Seq[String]]("foo")
val checkFoo = inputKey[Unit]("check contents of foo")
lazy val root = (project in file("."))
.settings(
foo := Nil,
checkFoo := {
val arguments = Def.spaceDelimited("").parsed.mkString(" ")
assert(foo.value.contains(arguments))
},
libraryDependencies += scalatest % Test,
// testOptions in Test += Tests.Argument(TestFrameworks.ScalaTest, "-f", "result.txt", "-eNDXEHLO")
testOptions in Configurations.Test ++= {

View File

@ -26,3 +26,7 @@ $ touch failure3
$ delete failure3
> set Compile / scalacOptions += "-Xfatal-warnings"
> set foo += "an argument with spaces"
> checkFoo an argument with spaces

View File

@ -27,7 +27,7 @@ final class SbtHandler(remoteSbtCreator: RemoteSbtCreator) extends StatementHand
def apply(command: String, arguments: List[String], i: Option[SbtInstance]): Option[SbtInstance] =
onSbtInstance(i) { (_, server) =>
send((command :: arguments.map(escape)).mkString(" "), server)
send((command :: arguments).mkString(" "), server)
receive(s"$command failed", server)
}
@ -80,12 +80,4 @@ final class SbtHandler(remoteSbtCreator: RemoteSbtCreator) extends StatementHand
catch { case _: SocketException => throw new TestFailed("Remote sbt initialization failed") }
p
}
// if the argument contains spaces, enclose it in quotes, quoting backslashes and quotes
def escape(argument: String) = {
import java.util.regex.Pattern.{ quote => q }
if (argument.contains(" "))
"\"" + argument.replaceAll(q("""\"""), """\\""").replaceAll(q("\""), "\\\"") + "\""
else argument
}
}