From 188349ff54ada2f35930c0dc21e660bc6e42b1f5 Mon Sep 17 00:00:00 2001 From: Patrik Svensson Date: Sun, 5 Jun 2016 22:16:48 +0200 Subject: [PATCH] Fixed argument parsing bug. Closes #671 --- .../Unit/Arguments/ArgumentTokenizerTests.cs | 16 ++++++++++++++++ src/Cake/Arguments/ArgumentTokenizer.cs | 11 +++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Cake.Tests/Unit/Arguments/ArgumentTokenizerTests.cs b/src/Cake.Tests/Unit/Arguments/ArgumentTokenizerTests.cs index 58447dfa63..c9240251d4 100644 --- a/src/Cake.Tests/Unit/Arguments/ArgumentTokenizerTests.cs +++ b/src/Cake.Tests/Unit/Arguments/ArgumentTokenizerTests.cs @@ -81,6 +81,22 @@ public void Should_Parse_Multiple_Mixed_Arguments() Assert.Equal("-verbosity", result[2]); Assert.Equal("\"diagnostic\"", result[3]); } + + [Fact] + public void Should_Parse_Part_That_Contains_Quotes_With_Space_In_It() + { + // Given + const string input = @"cake.exe build.cake -target=""te st"""; + + // When + var result = ArgumentTokenizer.Tokenize(input).ToArray(); + + // Then + Assert.Equal(3, result.Length); + Assert.Equal("cake.exe", result[0]); + Assert.Equal("build.cake", result[1]); + Assert.Equal("-target=\"te st\"", result[2]); + } } } } \ No newline at end of file diff --git a/src/Cake/Arguments/ArgumentTokenizer.cs b/src/Cake/Arguments/ArgumentTokenizer.cs index 850f2d9ca8..3018fa6bfd 100644 --- a/src/Cake/Arguments/ArgumentTokenizer.cs +++ b/src/Cake/Arguments/ArgumentTokenizer.cs @@ -55,11 +55,18 @@ private static string Read(StringReader reader) accumulator.Append((char)reader.Read()); while (reader.Peek() != -1) { - if ((char)reader.Peek() == ' ') + if ((char)reader.Peek() == '\"') + { + accumulator.Append(ReadQuote(reader)); + } + else if ((char)reader.Peek() == ' ') { break; } - accumulator.Append((char)reader.Read()); + else + { + accumulator.Append((char)reader.Read()); + } } return accumulator.ToString(); }