Skip to content

Commit

Permalink
Merge pull request #955 from patriksvensson/feature/GH671
Browse files Browse the repository at this point in the history
GH671: Fixed argument parsing bug.
  • Loading branch information
gep13 committed Jun 6, 2016
2 parents c87814b + 188349f commit 004912d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/Cake.Tests/Unit/Arguments/ArgumentTokenizerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
}
}
}
}
11 changes: 9 additions & 2 deletions src/Cake/Arguments/ArgumentTokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down

0 comments on commit 004912d

Please sign in to comment.