Visitar URL original
Preserve verbatim stop-parsing argument passing by huong8373tt-beep · Pull Request #28162 · PowerShell/PowerShell · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ internal override object GetDefaultParameterValue(string name)
return null;
}

internal bool HasVerbatimArgumentMarker { get; private set; }

internal void BindParameters(Collection<CommandParameterInternal> parameters)
{
bool sawVerbatimArgumentMarker = false;
Expand Down Expand Up @@ -98,6 +100,7 @@ internal void BindParameters(Collection<CommandParameterInternal> parameters)
object argValue = parameter.ArgumentValue;
if (string.Equals("--%", argValue as string, StringComparison.OrdinalIgnoreCase))
{
HasVerbatimArgumentMarker = true;
sawVerbatimArgumentMarker = true;
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ internal NativeArgumentPassingStyle ArgumentPassingStyle
}
}

internal bool HasVerbatimArgumentMarker
{
get
{
return ((NativeCommandParameterBinder)DefaultParameterBinder).HasVerbatimArgumentMarker;
}
}

/// <summary>
/// Passes the binding directly through to the parameter binder.
/// It does no verification against metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1585,7 +1585,8 @@ private void ProcessOutputRecord(ProcessOutputObject outputValue)
/// </summary>
/// <param name="filePath"></param>
private bool UseSpecialArgumentPassing(string filePath) =>
NativeParameterBinderController.ArgumentPassingStyle switch
(Platform.IsWindows && NativeParameterBinderController.HasVerbatimArgumentMarker)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks — addressed in a8d7868. The binder now detects --% before any parameter formatting and applies the effective Legacy style across the full Windows native-command argument construction. Added regression coverage for the mode-sensitive array case before the marker (testexe -echoargs 1, 2 --% tail) under Standard and Windows modes.

|| NativeParameterBinderController.ArgumentPassingStyle switch
{
NativeArgumentPassingStyle.Legacy => true,
NativeArgumentPassingStyle.Windows => ShouldUseLegacyPassingStyle(filePath),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,28 @@ Describe "find.exe uses legacy behavior on Windows" -Tag 'CI' {
}
}

Describe "Stop-parsing uses legacy native argument passing" -Tag 'CI' {
BeforeAll {
$currentSetting = $PSNativeCommandArgumentPassing
}

AfterAll {
$PSNativeCommandArgumentPassing = $currentSetting
}

It "Preserves escaped quotes after '--%' with <argumentListValue> argument passing" -Skip:(-not $IsWindows) -TestCases @(
@{ argumentListValue = 'Standard' }
@{ argumentListValue = 'Windows' }
) {
param($argumentListValue)

$PSNativeCommandArgumentPassing = $argumentListValue
$lines = @(Invoke-Expression 'testexe -echoargs --% /p:Category=\"CI,Nightly\"')

$lines | Should -BeExactly 'Arg 0 is </p:Category="CI,Nightly">'
}
}

foreach ( $argumentListValue in "Standard","Legacy","Windows" ) {
$PSNativeCommandArgumentPassing = $argumentListValue
Describe "Native Command Arguments (${PSNativeCommandArgumentPassing})" -tags "CI" {
Expand Down