diff --git a/Source/Tools/Flax.Build.Tests/TestCommandLine.cs b/Source/Tools/Flax.Build.Tests/TestCommandLine.cs index db530b70d..905dc99af 100644 --- a/Source/Tools/Flax.Build.Tests/TestCommandLine.cs +++ b/Source/Tools/Flax.Build.Tests/TestCommandLine.cs @@ -12,6 +12,7 @@ namespace Flax.Build.Tests [Test, Sequential] public void TestParseOptionOnly([Values( "-something", + "something", " \t \t-\t \tsomething\t ", "-something=")] string commandLine) @@ -25,6 +26,11 @@ namespace Flax.Build.Tests [Test, Sequential] public void TestParseOneValue([Values( "-something=value", + "something=value", + "-something=\"value\"", + "-something=\\\"value\\\"", + "\"-something=\"value\"\"", + "\"-something=\\\"value\\\"\"", " \t \t-\t \tsomething\t =value ", "-something=value ")] string commandLine) diff --git a/Source/Tools/Flax.Build/CommandLine.cs b/Source/Tools/Flax.Build/CommandLine.cs index 91b6febce..f0a631145 100644 --- a/Source/Tools/Flax.Build/CommandLine.cs +++ b/Source/Tools/Flax.Build/CommandLine.cs @@ -249,6 +249,8 @@ namespace Flax.Build var wholeQuote = commandLine[i] == '\"'; if (wholeQuote) i++; + if (i == length) + break; if (commandLine[i] == '-') i++; else if (commandLine[i] == '/') @@ -279,7 +281,7 @@ namespace Flax.Build }); if (wholeQuote) i++; - if (i != length && commandLine[i] != '\"') + if (i < length && commandLine[i] != '\"') i++; continue; } @@ -287,23 +289,36 @@ namespace Flax.Build // Read value i++; int valueStart, valueEnd; - if (commandLine[i] == '\"') + if (commandLine.Length > i + 1 && commandLine[i] == '\\' && commandLine[i + 1] == '\"') { - valueStart = i + 1; + valueStart = i + 2; i++; - while (i < length && commandLine[i] != '\"') + while (i + 1 < length && commandLine[i] != '\\' && commandLine[i + 1] != '\"') i++; valueEnd = i; - i++; + i += 2; + if (wholeQuote) + { + while (i < length && commandLine[i] != '\"') + i++; + i++; + } } - else if (commandLine[i] == '\'') + else if (commandLine[i] == '\"' || commandLine[i] == '\'') { + var quoteChar = commandLine[i]; valueStart = i + 1; i++; - while (i < length && commandLine[i] != '\'') + while (i < length && commandLine[i] != quoteChar) i++; valueEnd = i; i++; + if (wholeQuote) + { + while (i < length && commandLine[i] != '\"') + i++; + i++; + } } else if (wholeQuote) { @@ -321,10 +336,13 @@ namespace Flax.Build valueEnd = i; } string value = commandLine.Substring(valueStart, valueEnd - valueStart); + value = value.Trim(); + if (value.StartsWith("\\\"") && value.EndsWith("\\\"")) + value = value.Substring(2, value.Length - 4); options.Add(new Option { Name = name, - Value = value.Trim() + Value = value }); }