Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -4629,22 +4629,19 @@ private static List<CompletionResult> GetFileSystemProviderResults(
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)
Expand Down
5 changes: 5 additions & 0 deletions test/powershell/Host/TabCompletion/TabCompletion.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down