Fix UNC path completion regression (#20419)

This commit is contained in:
MartinGC94 2023-10-17 00:43:48 +02:00 committed by GitHub
parent 2e5bd015c3
commit 6176fd3fcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View File

@ -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)

View File

@ -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