Skip to content

Commit 8a4a18b

Browse files
committed
Always quote non-cmd parameters and values
1 parent 87ee210 commit 8a4a18b

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ jobs:
140140
141141
- run: |
142142
if [ "${{ matrix.shell }}" == "default" ]; then
143-
dotnet r test --verbose
143+
dotnet r test --verbose -- --logger "trx;LogFilePrefix=${{ matrix.os }}-integration-tests"
144144
else
145-
dotnet r test --verbose --script-shell "${{ matrix.shell }}"
145+
dotnet r test --verbose --script-shell "${{ matrix.shell }}" -- --logger "trx;LogFilePrefix=${{ matrix.os }}-integration-tests"
146146
fi
147147
shell: bash
148148

src/ArgumentBuilder.cs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,9 @@ public static string ConcatinateCommandAndArgArrayForDisplay(
107107

108108
private static void EscapeSingleArg(ref ValueStringBuilder sb, ReadOnlySpan<char> arg)
109109
{
110-
var needsQuotes = arg.Length == 0 || ArgumentContainsWhitespace(arg);
111-
var isQuoted = needsQuotes || IsSurroundedWithQuotes(arg);
110+
var isQuoted = IsSurroundedWithQuotes(arg);
112111

113-
if (needsQuotes)
114-
{
115-
sb.Append(Quote);
116-
}
112+
sb.Append(Quote);
117113

118114
for (var i = 0; i < arg.Length; ++i)
119115
{
@@ -157,10 +153,7 @@ private static void EscapeSingleArg(ref ValueStringBuilder sb, ReadOnlySpan<char
157153
}
158154
}
159155

160-
if (needsQuotes)
161-
{
162-
sb.Append(Quote);
163-
}
156+
sb.Append(Quote);
164157
}
165158

166159
/// <summary>

test/ArgumentBuilderTests.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ public class ArgumentBuilderTests
88
[InlineData("cm \"d\"", null, "cm \"d\"")]
99
[InlineData("c m d", null, "c m d")]
1010
[InlineData("c m d", new string[0], "c m d")]
11-
[InlineData("c m d", new[] { "one", "two", "three" }, "c m d one two three")]
11+
[InlineData("c m d", new[] { "one", "two", "three" }, "c m d \"one\" \"two\" \"three\"")]
1212
[InlineData("c m d", new[] { "line1\nline2", "word1\tword2" }, "c m d \"line1\nline2\" \"word1\tword2\"")]
1313
[InlineData("c m d", new[] { "with spaces" }, "c m d \"with spaces\"")]
14-
[InlineData("c m d", new[] { @"with\backslash" }, @"c m d with\backslash")]
15-
[InlineData("c m d", new[] { @"""quotedwith\backslash""" }, @"c m d \""quotedwith\backslash\""")]
16-
[InlineData("c m d", new[] { @"C:\Users\" }, @"c m d C:\Users\")]
17-
[InlineData("c m d", new[] { @"C:\Program Files\dotnet\" }, @"c m d ""C:\Program Files\dotnet\\""")]
18-
[InlineData("c m d", new[] { @"backslash\""preceedingquote" }, @"c m d backslash\\\""preceedingquote")]
14+
[InlineData("c m d", new[] { @"with\backslash" }, @"c m d ""with\backslash""")]
15+
[InlineData("c m d", new[] { @"""quotedwith\backslash""" }, @"c m d ""\""quotedwith\backslash\""""")]
16+
[InlineData("c m d", new[] { @"C:\Users\" }, @"c m d ""C:\Users\""")]
17+
[InlineData("c m d", new[] { @"C:\Program Files\dotnet\" }, @"c m d ""C:\Program Files\dotnet\""")]
18+
[InlineData("c m d", new[] { @"backslash\""preceedingquote" }, @"c m d ""backslash\\\""preceedingquote""")]
1919
[InlineData("c m d", new[] { @""" hello """ }, @"c m d ""\"" hello \""""")]
2020
public void EscapeAndConcatenateCommandAndArgArrayForProcessStart(string command, string[] args, string expected)
2121
{

0 commit comments

Comments
 (0)