Skip to content

Commit ed5935f

Browse files
committed
Remove caret escaping from cmd commands
1 parent 1edb2e9 commit ed5935f

File tree

4 files changed

+22
-18
lines changed

4 files changed

+22
-18
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ jobs:
159159
name: integration-test-results
160160
path: ./.coverage/*.trx
161161

162+
- run: dotnet r integration:ci --verbose -- --logger "trx;LogFilePrefix=ci test"
163+
162164
release:
163165
if: github.event_name == 'push'
164166

global.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
"test:release": "dotnet r test -- --configuration Release",
2020
"pack:release": "dotnet r pack -- --configuration Release",
2121

22+
// integration tests
23+
"integration:ci": "dotnet r clean && dotnet r clean:bin && dotnet build && dotnet test --no-build",
24+
2225
// test scripts
2326
"info": "dotnet r dotnet:version && dotnet r dotnet:info",
2427
"dotnet:info": "dotnet --info",

src/ArgumentBuilder.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ public static string EscapeAndConcatenateCommandAndArgArrayForCmdProcessStart(
6262
{
6363
var sb = new ValueStringBuilder(stackalloc char[256]);
6464

65-
EscapeArgForCmd(ref sb, command, quoteValue: false);
65+
sb.Append(command);
6666

6767
if (args is not null)
6868
{
@@ -71,7 +71,7 @@ public static string EscapeAndConcatenateCommandAndArgArrayForCmdProcessStart(
7171
sb.Append(Caret);
7272
sb.Append(Space);
7373

74-
EscapeArgForCmd(ref sb, args[i], quoteValue: true);
74+
EscapeArgForCmd(ref sb, args[i]);
7575
}
7676
}
7777

@@ -165,10 +165,9 @@ private static void EscapeSingleArg(ref ValueStringBuilder sb, ReadOnlySpan<char
165165
/// </remarks>
166166
/// <param name="sb">The <seealso cref="ValueStringBuilder"/> to append to.</param>
167167
/// <param name="argument">The argument to escape.</param>
168-
/// <param name="quoteValue">If the value should be wrapped in quotes if it contains whitespace.</param>
169-
private static void EscapeArgForCmd(ref ValueStringBuilder sb, ReadOnlySpan<char> argument, bool quoteValue)
168+
private static void EscapeArgForCmd(ref ValueStringBuilder sb, ReadOnlySpan<char> argument)
170169
{
171-
var quoted = quoteValue && ArgumentContainsWhitespace(argument);
170+
var quoted = ArgumentContainsWhitespace(argument);
172171

173172
if (quoted)
174173
{

test/ArgumentBuilderTests.cs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@ public void EscapeAndConcatenateCommandAndArgArrayForProcessStart(string command
2727
}
2828

2929
[Theory]
30-
[InlineData("cmd", null, "^c^m^d")]
31-
[InlineData("cm \"d\"", null, "^c^m^ ^\"^d^\"")]
32-
[InlineData("c m d", null, "^c^ ^m^ ^d")]
33-
[InlineData("c m d", new string[0], "^c^ ^m^ ^d")]
34-
[InlineData("c m d", new[] { "one", "two", "three" }, "^c^ ^m^ ^d^ ^o^n^e^ ^t^w^o^ ^t^h^r^e^e")]
35-
[InlineData("c m d", new[] { "line1\nline2", "word1\tword2" }, "^c^ ^m^ ^d^ ^\"^l^i^n^e^1^\n^l^i^n^e^2^\"^ ^\"^w^o^r^d^1^\t^w^o^r^d^2^\"")]
36-
[InlineData("c m d", new[] { "with spaces" }, "^c^ ^m^ ^d^ ^\"^w^i^t^h^ ^s^p^a^c^e^s^\"")]
37-
[InlineData("c m d", new[] { @"with\backslash" }, @"^c^ ^m^ ^d^ ^w^i^t^h^\^b^a^c^k^s^l^a^s^h")]
38-
[InlineData("c m d", new[] { @"""quotedwith\backslash""" }, @"^c^ ^m^ ^d^ ^""^q^u^o^t^e^d^w^i^t^h^\^b^a^c^k^s^l^a^s^h^""")]
39-
[InlineData("c m d", new[] { @"C:\Users\" }, @"^c^ ^m^ ^d^ ^C^:^\^U^s^e^r^s^\")]
40-
[InlineData("c m d", new[] { @"C:\Program Files\dotnet\" }, @"^c^ ^m^ ^d^ ^""^C^:^\^P^r^o^g^r^a^m^ ^F^i^l^e^s^\^d^o^t^n^e^t^\^""")]
41-
[InlineData("c m d", new[] { @"backslash\""preceedingquote" }, @"^c^ ^m^ ^d^ ^b^a^c^k^s^l^a^s^h^\^""^p^r^e^c^e^e^d^i^n^g^q^u^o^t^e")]
42-
[InlineData("c m d", new[] { @""" hello """ }, @"^c^ ^m^ ^d^ ^""^""^ ^h^e^l^l^o^ ^""^""")]
30+
[InlineData("cmd", null, "cmd")]
31+
[InlineData("cm \"d\"", null, "cm \"d\"")]
32+
[InlineData("c m d", null, "c m d")]
33+
[InlineData("c m d", new string[0], "c m d")]
34+
[InlineData("c m d", new[] { "one", "two", "three" }, "c m d^ ^o^n^e^ ^t^w^o^ ^t^h^r^e^e")]
35+
[InlineData("c m d", new[] { "line1\nline2", "word1\tword2" }, "c m d^ ^\"^l^i^n^e^1^\n^l^i^n^e^2^\"^ ^\"^w^o^r^d^1^\t^w^o^r^d^2^\"")]
36+
[InlineData("c m d", new[] { "with spaces" }, "c m d^ ^\"^w^i^t^h^ ^s^p^a^c^e^s^\"")]
37+
[InlineData("c m d", new[] { @"with\backslash" }, @"c m d^ ^w^i^t^h^\^b^a^c^k^s^l^a^s^h")]
38+
[InlineData("c m d", new[] { @"""quotedwith\backslash""" }, @"c m d^ ^""^q^u^o^t^e^d^w^i^t^h^\^b^a^c^k^s^l^a^s^h^""")]
39+
[InlineData("c m d", new[] { @"C:\Users\" }, @"c m d^ ^C^:^\^U^s^e^r^s^\")]
40+
[InlineData("c m d", new[] { @"C:\Program Files\dotnet\" }, @"c m d^ ^""^C^:^\^P^r^o^g^r^a^m^ ^F^i^l^e^s^\^d^o^t^n^e^t^\^""")]
41+
[InlineData("c m d", new[] { @"backslash\""preceedingquote" }, @"c m d^ ^b^a^c^k^s^l^a^s^h^\^""^p^r^e^c^e^e^d^i^n^g^q^u^o^t^e")]
42+
[InlineData("c m d", new[] { @""" hello """ }, @"c m d^ ^""^""^ ^h^e^l^l^o^ ^""^""")]
4343
public void EscapeAndConcatenateCommandAndArgArrayForCmdProcessStart(string command, string[] args, string expected)
4444
{
4545
// Given / When

0 commit comments

Comments
 (0)