Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH671: Fixed argument parsing bug. #955

Merged
merged 1 commit into from
Jun 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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