diff --git a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs index 1c2e835b95..aa0e94a583 100644 --- a/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs +++ b/src/System.Management.Automation/engine/NativeCommandParameterBinder.cs @@ -165,7 +165,17 @@ namespace System.Management.Automation { if (argument != parameter.ParameterText) { - _argumentList.Add(parameter.ParameterText + argument); + // Only combine the text and argument if there was no space after the parameter, + // otherwise, add the parameter and arguments as separate elements. + if (parameter.SpaceAfterParameter) + { + _argumentList.Add(parameter.ParameterText); + _argumentList.Add(argument); + } + else + { + _argumentList.Add(parameter.ParameterText + argument); + } } } else diff --git a/test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 b/test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 index b4e92d4317..aead692cc6 100644 --- a/test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 +++ b/test/powershell/Language/Scripting/NativeExecution/NativeCommandArguments.Tests.ps1 @@ -239,6 +239,14 @@ foreach ( $argumentListValue in "Standard","Legacy","Windows" ) { $lines[1] | Should -BeExactly "Arg 1 is " } + It "Should handle when the ':' is the parameter value" { + $lines = testexe -echoargs awk -F: '{print $1}' + $lines.Count | Should -Be 3 + $lines[0] | Should -BeExactly 'Arg 0 is ' + $lines[1] | Should -BeExactly 'Arg 1 is <-F:>' + $lines[2] | Should -BeExactly 'Arg 2 is <{print $1}>' + } + It "Should handle DOS style arguments" { $lines = testexe -echoargs /arg1 /c:"a string" $lines.Count | Should -Be 2