From ca8fd354bd7da44bc86260e444a1cd4a041a1350 Mon Sep 17 00:00:00 2001 From: Amina Adewusi Date: Fri, 4 Feb 2022 17:52:39 +0000 Subject: [PATCH] Fixes parsing command args quote problem Fixes #6802. --- .../main/scala/sbt/internal/util/complete/Parsers.scala | 7 ++++++- internal/util-complete/src/test/scala/ParserTest.scala | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/util-complete/src/main/scala/sbt/internal/util/complete/Parsers.scala b/internal/util-complete/src/main/scala/sbt/internal/util/complete/Parsers.scala index 884aecc9a..15a1f2dcb 100644 --- a/internal/util-complete/src/main/scala/sbt/internal/util/complete/Parsers.scala +++ b/internal/util-complete/src/main/scala/sbt/internal/util/complete/Parsers.scala @@ -202,7 +202,7 @@ trait Parsers { * Parses a potentially quoted String value. The value may be verbatim quoted ([[StringVerbatim]]), * quoted with interpreted escapes ([[StringEscapable]]), or unquoted ([[NotQuoted]]). */ - lazy val StringBasic = StringVerbatim | StringEscapable | NotQuoted + lazy val StringBasic = StringVerbatim | StringEscapable | NotQuoted | NotQuotedThenQuoted /** * Parses a verbatim quoted String value, discarding the quotes in the result. This kind of quoted text starts with triple quotes `"""` @@ -270,6 +270,11 @@ trait Parsers { /** Parses an unquoted, non-empty String value that cannot start with a double quote and cannot contain whitespace.*/ lazy val NotQuoted = (NotDQuoteSpaceClass ~ OptNotSpace) map { case (c, s) => c.toString + s } + /** Parses a non-empty String value that cannot start with a double quote, but includes double quotes.*/ + lazy val NotQuotedThenQuoted = (NotQuoted ~ StringEscapable) map { + case (s1, s2) => s"""$s1\"$s2\"""" + } + /** * Applies `rep` zero or more times, separated by `sep`. * The result is the (possibly empty) sequence of results from the multiple `rep` applications. The `sep` results are discarded. diff --git a/internal/util-complete/src/test/scala/ParserTest.scala b/internal/util-complete/src/test/scala/ParserTest.scala index 49f99056f..4694f974a 100644 --- a/internal/util-complete/src/test/scala/ParserTest.scala +++ b/internal/util-complete/src/test/scala/ParserTest.scala @@ -119,6 +119,8 @@ object ParserTest extends Properties("Completing Parser") { property("repeatDep requires at least one token") = !matches(repeat, "") property("repeatDep accepts one token") = matches(repeat, colors.toSeq.head) property("repeatDep accepts two tokens") = matches(repeat, colors.toSeq.take(2).mkString(" ")) + property("parses string that doesn't start with quotes, but includes quotes within it") = + matches(StringBasic, "-Dsilicon:z3ConfigArgs=\"model=true model_validate=true\"") } object ParserExample { val ws = charClass(_.isWhitespace, "whitespace").+