mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Properly escape trailing backslash so that it doesn't end up escaping the quotes (#4965)
The native command receives the arg ".\test 1" as .\test 1" as the last \" is treated as escaping the quotes. Fix is to add an extra backslash to escape the last enclosing quote.
This commit is contained in:
+14
-2
@@ -8,7 +8,7 @@ Describe "Native Command Arguments" -tags "CI" {
|
||||
It "Should handle quoted spaces correctly" {
|
||||
$a = 'a"b c"d'
|
||||
$lines = testexe -echoargs $a 'a"b c"d' a"b c"d
|
||||
($lines | measure).Count | Should Be 3
|
||||
$lines.Count | Should Be 3
|
||||
$lines[0] | Should Be 'Arg 0 is <ab cd>'
|
||||
$lines[1] | Should Be 'Arg 1 is <ab cd>'
|
||||
$lines[2] | Should Be 'Arg 2 is <ab cd>'
|
||||
@@ -27,8 +27,20 @@ Describe "Native Command Arguments" -tags "CI" {
|
||||
# looking at how it got the arguments.
|
||||
It "Should handle spaces between escaped quotes" {
|
||||
$lines = testexe -echoargs 'a\"b c\"d' "a\`"b c\`"d"
|
||||
($lines | measure).Count | Should Be 2
|
||||
$lines.Count | Should Be 2
|
||||
$lines[0] | Should Be 'Arg 0 is <a"b c"d>'
|
||||
$lines[1] | Should Be 'Arg 1 is <a"b c"d>'
|
||||
}
|
||||
|
||||
It "Should correctly quote paths with spaces: <arguments>" -TestCases @(
|
||||
@{arguments = "'.\test 1\' `".\test 2\`"" ; expected = @(".\test 1\",".\test 2\")},
|
||||
@{arguments = "'.\test 1\\\' `".\test 2\\`""; expected = @(".\test 1\\\",".\test 2\\")}
|
||||
) {
|
||||
param($arguments, $expected)
|
||||
$lines = Invoke-Expression "testexe -echoargs $arguments"
|
||||
$lines.Count | Should Be $expected.Count
|
||||
for ($i = 0; $i -lt $lines.Count; $i++) {
|
||||
$lines[$i] | Should Be "Arg $i is <$($expected[$i])>"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user