diff --git a/src/CommandLineUtils/Utilities/ArgumentEscaper.cs b/src/CommandLineUtils/Utilities/ArgumentEscaper.cs index 68650c12..aa761d77 100644 --- a/src/CommandLineUtils/Utilities/ArgumentEscaper.cs +++ b/src/CommandLineUtils/Utilities/ArgumentEscaper.cs @@ -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) diff --git a/test/CommandLineUtils.Tests/ArgumentEscaperTests.cs b/test/CommandLineUtils.Tests/ArgumentEscaperTests.cs index 1dc2b338..343cb20b 100644 --- a/test/CommandLineUtils.Tests/ArgumentEscaperTests.cs +++ b/test/CommandLineUtils.Tests/ArgumentEscaperTests.cs @@ -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));