mirror of
https://github.com/PowerShell/PowerShell.git
synced 2024-11-23 17:53:58 +08:00
Fix UNC path completion regression (#20419)
This commit is contained in:
parent
2e5bd015c3
commit
6176fd3fcf
@ -4629,22 +4629,19 @@ namespace System.Management.Automation
|
||||
string basePath;
|
||||
if (!relativePaths)
|
||||
{
|
||||
string providerName = $"{provider.ModuleName}\\{provider.Name}::";
|
||||
if (pathInfo.Path.StartsWith(providerName, StringComparison.OrdinalIgnoreCase))
|
||||
if (pathInfo.Drive is null)
|
||||
{
|
||||
basePath = pathInfo.Path.Substring(providerName.Length);
|
||||
basePath = dirInfo.FullName;
|
||||
}
|
||||
else
|
||||
{
|
||||
providerName = $"{provider.Name}::";
|
||||
if (pathInfo.Path.StartsWith(providerName, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
basePath = pathInfo.Path.Substring(providerName.Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
basePath = pathInfo.Path;
|
||||
}
|
||||
int stringStartIndex = pathInfo.Drive.Root.EndsWith(provider.ItemSeparator) && pathInfo.Drive.Root.Length > 1
|
||||
? pathInfo.Drive.Root.Length - 1
|
||||
: pathInfo.Drive.Root.Length;
|
||||
|
||||
basePath = pathInfo.Drive.VolumeSeparatedByColon
|
||||
? string.Concat(pathInfo.Drive.Name, ":", dirInfo.FullName.AsSpan(stringStartIndex))
|
||||
: string.Concat(pathInfo.Drive.Name, dirInfo.FullName.AsSpan(stringStartIndex));
|
||||
}
|
||||
|
||||
basePath = basePath.EndsWith(provider.ItemSeparator)
|
||||
|
@ -1276,6 +1276,11 @@ class InheritedClassTest : System.Attribute
|
||||
}
|
||||
}
|
||||
|
||||
It 'Should correct slashes in UNC path completion' -Skip:(!$IsWindows) {
|
||||
$Res = TabExpansion2 -inputScript 'Get-ChildItem //localhost/c$/Windows'
|
||||
$Res.CompletionMatches[0].CompletionText | Should -Be "'\\localhost\c$\Windows'"
|
||||
}
|
||||
|
||||
It 'Should keep custom drive names when completing file paths' {
|
||||
$TempDriveName = "asdf"
|
||||
$null = New-PSDrive -Name $TempDriveName -PSProvider FileSystem -Root $HOME
|
||||
|
Loading…
Reference in New Issue
Block a user