Skip to content

Commit f6ccb94

Browse files
authored
Resolved bug #1027 (#1045)
* Resolved bug #1027
1 parent fed6c16 commit f6ccb94

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

src/System.CommandLine.Tests/ResponseFileTests.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,5 +336,46 @@ public void Response_files_can_refer_to_other_response_files()
336336
result.FindResultFor(option3).GetValueOrDefault().Should().Be(3);
337337
result.Errors.Should().BeEmpty();
338338
}
339+
340+
[Fact]
341+
public void When_response_file_options_or_arguments_contain_trailing_spaces_they_are_ignored()
342+
{
343+
var responseFile = ResponseFile("--option1 ", "value1 ", "--option2\t", "2\t");
344+
345+
var option1 = new Option("--option1") { Argument = new Argument<string>() };
346+
var option2 = new Option("--option2") { Argument = new Argument<int>() };
347+
348+
var result = new RootCommand { option1, option2 }.Parse($"@{responseFile}");
349+
result.ValueForOption("--option1").Should().Be("value1");
350+
result.ValueForOption("--option2").Should().Be(2);
351+
}
352+
353+
[Fact]
354+
public void When_response_file_options_or_arguments_contain_leading_spaces_they_are_ignored()
355+
{
356+
var responseFile = ResponseFile(" --option1", " value1", "\t--option2", "\t2");
357+
358+
var option1 = new Option("--option1") { Argument = new Argument<string>() };
359+
var option2 = new Option("--option2") { Argument = new Argument<int>() };
360+
361+
var result = new RootCommand { option1, option2 }.Parse($"@{responseFile}");
362+
result.ValueForOption("--option1").Should().Be("value1");
363+
result.ValueForOption("--option2").Should().Be(2);
364+
result.Errors.Should().BeEmpty();
365+
}
366+
367+
[Fact]
368+
public void When_response_file_options_or_arguments_contain_trailing_and_leading_spaces_they_are_ignored()
369+
{
370+
var responseFile = ResponseFile(" --option1 ", " value1 ", "\t--option2\t", "\t2\t");
371+
372+
var option1 = new Option("--option1") { Argument = new Argument<string>() };
373+
var option2 = new Option("--option2") { Argument = new Argument<int>() };
374+
375+
var result = new RootCommand { option1, option2 }.Parse($"@{responseFile}");
376+
result.ValueForOption("--option1").Should().Be("value1");
377+
result.ValueForOption("--option2").Should().Be(2);
378+
result.Errors.Should().BeEmpty();
379+
}
339380
}
340381
}

src/System.CommandLine/Parsing/StringExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ IEnumerable<string> SplitLine(string line)
546546
{
547547
case ResponseFileHandling.ParseArgsAsLineSeparated:
548548

549-
yield return line;
549+
yield return arg;
550550

551551
break;
552552
case ResponseFileHandling.ParseArgsAsSpaceSeparated:

0 commit comments

Comments
 (0)