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

Fix parsing values which starts with dash, but has whitespace inside. #892

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion src/CommandLine/Core/Tokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static class Tokenizer
Action<Error> onError = errors.Add;

var tokens = (from arg in arguments
from token in !arg.StartsWith("-", StringComparison.Ordinal)
from token in (!arg.StartsWith("-", StringComparison.Ordinal) || (arg.Contains(" ") && !arg.Contains("=")))
? new[] { Token.Value(arg) }
: arg.StartsWith("--", StringComparison.Ordinal)
? TokenizeLongName(arg, onError)
Expand Down
21 changes: 21 additions & 0 deletions tests/CommandLine.Tests/Unit/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,27 @@ public void Parse_options_with_double_dash()
// Teardown
}

[Fact]
public void Parse_options_with_whitespace_and_double_dash()
{
// Fixture setup
var expectedOptions = new Simple_Options
{
StringValue = "--astring value",
IntSequence = Enumerable.Empty<int>(),
};
var sut = new Parser();

// Exercize system
var result =
sut.ParseArguments<Simple_Options>(
new[] { "--stringvalue", "--astring value" });

// Verify outcome
((Parsed<Simple_Options>)result).Value.Should().BeEquivalentTo(expectedOptions);
// Teardown
}

[Fact]
public void Parse_options_with_repeated_value_in_values_sequence_and_option()
{
Expand Down