Skip to content

Commit

Permalink
Escape empty arguments.
Browse files Browse the repository at this point in the history
  • Loading branch information
ejball committed Apr 25, 2019
1 parent cf83608 commit 0ed6092
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/CommandLineUtils/Utilities/ArgumentEscaper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static string EscapeSingleArg(string arg)
{
var sb = new StringBuilder();

var needsQuotes = ContainsWhitespace(arg);
var needsQuotes = arg.Length == 0 || ContainsWhitespace(arg);
var isQuoted = needsQuotes || IsSurroundedWithQuotes(arg);

if (needsQuotes)
Expand Down
1 change: 1 addition & 0 deletions test/CommandLineUtils.Tests/ArgumentEscaperTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ArgumentEscaperTests
[InlineData(new[] { @"C:\Program Files\dotnet\" }, @"""C:\Program Files\dotnet\\""")]
[InlineData(new[] { @"backslash\""preceedingquote" }, @"backslash\\\""preceedingquote")]
[InlineData(new[] { @""" hello nate """ }, @"""\"" hello nate \""""")]
[InlineData(new[] { "one", "", "three" }, "one \"\" three")]
public void EscapesArguments(string[] args, string expected)
{
Assert.Equal(expected, ArgumentEscaper.EscapeAndConcatenate(args));
Expand Down

0 comments on commit 0ed6092

Please sign in to comment.