mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Make experimental feature PSNativeCommandArgumentPassing stable (#18044)
This commit is contained in:
@@ -2,7 +2,6 @@
|
||||
"PSAnsiRenderingFileInfo",
|
||||
"PSCommandNotFoundSuggestion",
|
||||
"PSLoadAssemblyFromNativeCode",
|
||||
"PSNativeCommandArgumentPassing",
|
||||
"PSNativeCommandErrorActionPreference",
|
||||
"PSStrictModeAssignment",
|
||||
"PSSubsystemPluginModel"
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
"PSAnsiRenderingFileInfo",
|
||||
"PSCommandNotFoundSuggestion",
|
||||
"PSLoadAssemblyFromNativeCode",
|
||||
"PSNativeCommandArgumentPassing",
|
||||
"PSNativeCommandErrorActionPreference",
|
||||
"PSStrictModeAssignment",
|
||||
"PSSubsystemPluginModel"
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace System.Management.Automation
|
||||
#region Const Members
|
||||
|
||||
internal const string EngineSource = "PSEngine";
|
||||
internal const string PSNativeCommandArgumentPassingFeatureName = "PSNativeCommandArgumentPassing";
|
||||
internal const string PSNativeCommandErrorActionPreferenceFeatureName = "PSNativeCommandErrorActionPreference";
|
||||
internal const string PSStrictModeAssignment = "PSStrictModeAssignment";
|
||||
|
||||
@@ -112,9 +111,6 @@ namespace System.Management.Automation
|
||||
new ExperimentalFeature(
|
||||
name: "PSSubsystemPluginModel",
|
||||
description: "A plugin model for registering and un-registering PowerShell subsystems"),
|
||||
new ExperimentalFeature(
|
||||
name: PSNativeCommandArgumentPassingFeatureName,
|
||||
description: "Use ArgumentList when invoking a native command"),
|
||||
new ExperimentalFeature(
|
||||
name: "PSLoadAssemblyFromNativeCode",
|
||||
description: "Expose an API to allow assembly loading from native code"),
|
||||
|
||||
@@ -4161,13 +4161,7 @@ param(
|
||||
}
|
||||
else {
|
||||
$pagerCommand = 'less'
|
||||
# PSNativeCommandArgumentPassing arguments should be constructed differently.
|
||||
if ($EnabledExperimentalFeatures -contains 'PSNativeCommandArgumentPassing') {
|
||||
$pagerArgs = '-s','-P','Page %db?B of %D:.\. Press h for help or q to quit\.'
|
||||
}
|
||||
else {
|
||||
$pagerArgs = '-Ps""Page %db?B of %D:.\. Press h for help or q to quit\.$""'
|
||||
}
|
||||
$pagerArgs = '-s','-P','Page %db?B of %D:.\. Press h for help or q to quit\.'
|
||||
}
|
||||
|
||||
# Respect PAGER environment variable which allows user to specify a custom pager.
|
||||
@@ -4207,16 +4201,7 @@ param(
|
||||
$consoleWidth = [System.Math]::Max([System.Console]::WindowWidth, 20)
|
||||
|
||||
if ($pagerArgs) {
|
||||
# Start the pager arguments directly if the PSNativeCommandArgumentPassing feature is enabled.
|
||||
# Otherwise, supply pager arguments to an application without any PowerShell parsing of the arguments.
|
||||
# Leave environment variable to help user debug arguments supplied in $env:PAGER.
|
||||
if ($EnabledExperimentalFeatures -contains 'PSNativeCommandArgumentPassing') {
|
||||
$help | Out-String -Stream -Width ($consoleWidth - 1) | & $pagerCommand $pagerArgs
|
||||
}
|
||||
else {
|
||||
$env:__PSPAGER_ARGS = $pagerArgs
|
||||
$help | Out-String -Stream -Width ($consoleWidth - 1) | & $pagerCommand --% %__PSPAGER_ARGS%
|
||||
}
|
||||
$help | Out-String -Stream -Width ($consoleWidth - 1) | & $pagerCommand $pagerArgs
|
||||
}
|
||||
else {
|
||||
$help | Out-String -Stream -Width ($consoleWidth - 1) | & $pagerCommand
|
||||
@@ -4492,16 +4477,13 @@ end {
|
||||
new ArgumentTypeConverterAttribute(typeof(bool))));
|
||||
}
|
||||
|
||||
if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSNativeCommandArgumentPassingFeatureName))
|
||||
{
|
||||
builtinVariables.Add(
|
||||
new SessionStateVariableEntry(
|
||||
SpecialVariables.NativeArgumentPassing,
|
||||
Platform.IsWindows ? NativeArgumentPassingStyle.Windows : NativeArgumentPassingStyle.Standard,
|
||||
RunspaceInit.NativeCommandArgumentPassingDescription,
|
||||
ScopedItemOptions.None,
|
||||
new ArgumentTypeConverterAttribute(typeof(NativeArgumentPassingStyle))));
|
||||
}
|
||||
builtinVariables.Add(
|
||||
new SessionStateVariableEntry(
|
||||
SpecialVariables.NativeArgumentPassing,
|
||||
Platform.IsWindows ? NativeArgumentPassingStyle.Windows : NativeArgumentPassingStyle.Standard,
|
||||
RunspaceInit.NativeCommandArgumentPassingDescription,
|
||||
ScopedItemOptions.None,
|
||||
new ArgumentTypeConverterAttribute(typeof(NativeArgumentPassingStyle))));
|
||||
|
||||
BuiltInVariables = builtinVariables.ToArray();
|
||||
}
|
||||
|
||||
@@ -193,23 +193,17 @@ namespace System.Management.Automation
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ExperimentalFeature.IsEnabled(ExperimentalFeature.PSNativeCommandArgumentPassingFeatureName))
|
||||
try
|
||||
{
|
||||
try
|
||||
{
|
||||
// This will default to the new behavior if it is set to anything other than Legacy
|
||||
var preference = LanguagePrimitives.ConvertTo<NativeArgumentPassingStyle>(
|
||||
Context.GetVariableValue(SpecialVariables.NativeArgumentPassingVarPath, NativeArgumentPassingStyle.Standard));
|
||||
return preference;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The value is not convertable send back Legacy
|
||||
return NativeArgumentPassingStyle.Legacy;
|
||||
}
|
||||
var preference = LanguagePrimitives.ConvertTo<NativeArgumentPassingStyle>(
|
||||
Context.GetVariableValue(SpecialVariables.NativeArgumentPassingVarPath, NativeArgumentPassingStyle.Standard));
|
||||
return preference;
|
||||
}
|
||||
catch
|
||||
{
|
||||
// The value is not convertable send back Legacy
|
||||
return NativeArgumentPassingStyle.Legacy;
|
||||
}
|
||||
|
||||
return NativeArgumentPassingStyle.Legacy;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-14
@@ -4,9 +4,6 @@
|
||||
param()
|
||||
|
||||
Describe "Behavior is specific for each platform" -tags "CI" {
|
||||
BeforeAll {
|
||||
$skipTests = $EnabledExperimentalFeatures -notcontains 'PSNativeCommandArgumentPassing'
|
||||
}
|
||||
It "PSNativeCommandArgumentPassing is set to 'Windows' on Windows systems" -skip:(-not $IsWindows) {
|
||||
$PSNativeCommandArgumentPassing | Should -Be "Windows"
|
||||
}
|
||||
@@ -28,8 +25,7 @@ Describe "Behavior is specific for each platform" -tags "CI" {
|
||||
|
||||
Describe "tests for multiple languages and extensions" -tags "CI" {
|
||||
AfterAll {
|
||||
if (-not $IsWindows -or
|
||||
$EnabledExperimentalFeatures -notcontains 'PSNativeCommandArgumentPassing') {
|
||||
if (-not $IsWindows) {
|
||||
return
|
||||
}
|
||||
$PSNativeCommandArgumentPassing = $passingStyle
|
||||
@@ -126,7 +122,7 @@ echo Argument 4 is: ^<%4^>
|
||||
|
||||
# determine whether we should skip the tests we just defined
|
||||
# doing it in this order ensures that the test output will show each skipped test
|
||||
$skipTests = -not $IsWindows -or $EnabledExperimentalFeatures -notcontains 'PSNativeCommandArgumentPassing'
|
||||
$skipTests = -not $IsWindows
|
||||
if ($skipTests) {
|
||||
return
|
||||
}
|
||||
@@ -162,12 +158,7 @@ echo Argument 4 is: ^<%4^>
|
||||
|
||||
Describe "Will error correctly if an attempt to set variable to improper value" -tags "CI" {
|
||||
It "will error when setting variable incorrectly" {
|
||||
if ($EnabledExperimentalFeatures -contains 'PSNativeCommandArgumentPassing') {
|
||||
{ $global:PSNativeCommandArgumentPassing = "zzz" } | Should -Throw -ExceptionType System.Management.Automation.ArgumentTransformationMetadataException
|
||||
}
|
||||
else {
|
||||
Set-Test -State skipped -Because "Experimental feature 'PSNativeCommandArgumentPassing' is not enabled"
|
||||
}
|
||||
{ $global:PSNativeCommandArgumentPassing = "zzz" } | Should -Throw -ExceptionType System.Management.Automation.ArgumentTransformationMetadataException
|
||||
}
|
||||
}
|
||||
|
||||
@@ -203,7 +194,7 @@ foreach ( $argumentListValue in "Standard","Legacy","Windows" ) {
|
||||
$a = 'a"b c"d'
|
||||
$lines = testexe -echoargs $a 'a"b c"d' a"b c"d "a'b c'd"
|
||||
$lines.Count | Should -Be 4
|
||||
if (($EnabledExperimentalFeatures -contains 'PSNativeCommandArgumentPassing') -and $PSNativeCommandArgumentPassing -ne "Legacy") {
|
||||
if ($PSNativeCommandArgumentPassing -ne "Legacy") {
|
||||
$lines[0] | Should -BeExactly 'Arg 0 is <a"b c"d>'
|
||||
$lines[1] | Should -BeExactly 'Arg 1 is <a"b c"d>'
|
||||
}
|
||||
@@ -229,7 +220,7 @@ foreach ( $argumentListValue in "Standard","Legacy","Windows" ) {
|
||||
It "Should handle spaces between escaped quotes (ArgumentList=${PSNativeCommandArgumentPassing})" {
|
||||
$lines = testexe -echoargs 'a\"b c\"d' "a\`"b c\`"d"
|
||||
$lines.Count | Should -Be 2
|
||||
if (($EnabledExperimentalFeatures -contains 'PSNativeCommandArgumentPassing') -and $PSNativeCommandArgumentPassing -ne "Legacy") {
|
||||
if ($PSNativeCommandArgumentPassing -ne "Legacy") {
|
||||
$lines[0] | Should -BeExactly 'Arg 0 is <a\"b c\"d>'
|
||||
$lines[1] | Should -BeExactly 'Arg 1 is <a\"b c\"d>'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user