mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Revert "Change PSNativePSPathResolution to not be Experimental" (#13734)
* Revert "Change `PSNativePSPathResolution` to not be Experimental (#13522)"
This reverts commit 74c743d279.
This commit is contained in:
@@ -117,6 +117,9 @@ namespace System.Management.Automation
|
||||
new ExperimentalFeature(
|
||||
name: "PSCultureInvariantReplaceOperator",
|
||||
description: "Use culture invariant to-string convertor for lval in replace operator"),
|
||||
new ExperimentalFeature(
|
||||
name: "PSNativePSPathResolution",
|
||||
description: "Convert PSPath to filesystem path, if possible, for native commands"),
|
||||
new ExperimentalFeature(
|
||||
name: "PSNotApplyErrorActionToStderr",
|
||||
description: "Don't have $ErrorActionPreference affect stderr output"),
|
||||
|
||||
@@ -122,6 +122,14 @@ namespace System.Management.Automation
|
||||
break;
|
||||
}
|
||||
|
||||
// Prior to PSNativePSPathResolution experimental feature, a single quote worked the same as a double quote
|
||||
// so if the feature is not enabled, we treat any quotes as double quotes. When this feature is no longer
|
||||
// experimental, this code here needs to be removed.
|
||||
if (!ExperimentalFeature.IsEnabled("PSNativePSPathResolution") && stringConstantType == StringConstantType.SingleQuoted)
|
||||
{
|
||||
stringConstantType = StringConstantType.DoubleQuoted;
|
||||
}
|
||||
|
||||
AppendOneNativeArgument(Context, argValue, arrayLiteralAst, sawVerbatimArgumentMarker, stringConstantType);
|
||||
}
|
||||
}
|
||||
@@ -354,54 +362,57 @@ namespace System.Management.Automation
|
||||
/// <returns>Resolved PSPath if applicable otherwise the original path</returns>
|
||||
internal static string ResolvePath(string path, ExecutionContext context)
|
||||
{
|
||||
if (ExperimentalFeature.IsEnabled("PSNativePSPathResolution"))
|
||||
{
|
||||
#if !UNIX
|
||||
// on Windows, we need to expand ~ to point to user's home path
|
||||
if (string.Equals(path, "~", StringComparison.Ordinal) || path.StartsWith(TildeDirectorySeparator, StringComparison.Ordinal) || path.StartsWith(TildeAltDirectorySeparator, StringComparison.Ordinal))
|
||||
{
|
||||
try
|
||||
// on Windows, we need to expand ~ to point to user's home path
|
||||
if (string.Equals(path, "~", StringComparison.Ordinal) || path.StartsWith(TildeDirectorySeparator, StringComparison.Ordinal) || path.StartsWith(TildeAltDirectorySeparator, StringComparison.Ordinal))
|
||||
{
|
||||
ProviderInfo fileSystemProvider = context.EngineSessionState.GetSingleProvider(FileSystemProvider.ProviderName);
|
||||
return new StringBuilder(fileSystemProvider.Home)
|
||||
.Append(path.Substring(1))
|
||||
.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
|
||||
.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
// check if the driveName is an actual disk drive on Windows, if so, no expansion
|
||||
if (path.Length >= 2 && path[1] == ':')
|
||||
{
|
||||
foreach (var drive in DriveInfo.GetDrives())
|
||||
{
|
||||
if (drive.Name.StartsWith(new string(path[0], 1), StringComparison.OrdinalIgnoreCase))
|
||||
try
|
||||
{
|
||||
ProviderInfo fileSystemProvider = context.EngineSessionState.GetSingleProvider(FileSystemProvider.ProviderName);
|
||||
return new StringBuilder(fileSystemProvider.Home)
|
||||
.Append(path.Substring(1))
|
||||
.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar)
|
||||
.ToString();
|
||||
}
|
||||
catch
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (path.Contains(':'))
|
||||
{
|
||||
LocationGlobber globber = new LocationGlobber(context.SessionState);
|
||||
try
|
||||
// check if the driveName is an actual disk drive on Windows, if so, no expansion
|
||||
if (path.Length >= 2 && path[1] == ':')
|
||||
{
|
||||
ProviderInfo providerInfo;
|
||||
|
||||
// replace the argument with resolved path if it's a filesystem path
|
||||
string pspath = globber.GetProviderPath(path, out providerInfo);
|
||||
if (string.Equals(providerInfo.Name, FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
|
||||
foreach (var drive in DriveInfo.GetDrives())
|
||||
{
|
||||
path = pspath;
|
||||
if (drive.Name.StartsWith(new string(path[0], 1), StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return path;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch
|
||||
#endif
|
||||
|
||||
if (path.Contains(':'))
|
||||
{
|
||||
// if it's not a provider path, do nothing
|
||||
LocationGlobber globber = new LocationGlobber(context.SessionState);
|
||||
try
|
||||
{
|
||||
ProviderInfo providerInfo;
|
||||
|
||||
// replace the argument with resolved path if it's a filesystem path
|
||||
string pspath = globber.GetProviderPath(path, out providerInfo);
|
||||
if (string.Equals(providerInfo.Name, FileSystemProvider.ProviderName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
path = pspath;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// if it's not a provider path, do nothing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -67,6 +67,11 @@ Describe "Native Command Arguments" -tags "CI" {
|
||||
|
||||
Describe 'PSPath to native commands' {
|
||||
BeforeAll {
|
||||
$featureEnabled = $EnabledExperimentalFeatures.Contains('PSNativePSPathResolution')
|
||||
$originalDefaultParameterValues = $PSDefaultParameterValues.Clone()
|
||||
|
||||
$PSDefaultParameterValues["it:skip"] = (-not $featureEnabled)
|
||||
|
||||
if ($IsWindows) {
|
||||
$cmd = "cmd"
|
||||
$cmdArg1 = "/c"
|
||||
@@ -90,6 +95,8 @@ Describe 'PSPath to native commands' {
|
||||
}
|
||||
|
||||
AfterAll {
|
||||
$global:PSDefaultParameterValues = $originalDefaultParameterValues
|
||||
|
||||
Remove-Item -Path "env:/test var"
|
||||
Remove-Item -Path $filePath
|
||||
Remove-PSDrive -Name $complexDriveName
|
||||
|
||||
Reference in New Issue
Block a user