Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix wildcard globbing in root of device paths #19442

Merged
merged 6 commits into from
May 15, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Fix wildcard globbing in root of device paths
  • Loading branch information
MartinGC94 committed Apr 2, 2023
commit 14473b150f354d45a90c783a9fbcb8821c7d8e9e
9 changes: 9 additions & 0 deletions src/System.Management.Automation/engine/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,15 @@ internal static bool PathIsUnc(string path, bool networkOnly = false)
#endif
}

internal static bool PathIsDevicePath(string path)
{
#if UNIX
return false;
#else
return path.StartsWith(@"\\.\") || path.StartsWith(@"\\?\");
#endif
}

internal static readonly string PowerShellAssemblyStrongNameFormat =
"{0}, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4913,6 +4913,15 @@ protected override string GetParentPath(string path, string root)
// make sure we return two backslashes so it still results in a UNC path
parentPath = "\\\\";
}

MartinGC94 marked this conversation as resolved.
Show resolved Hide resolved
if (!parentPath.EndsWith(StringLiterals.DefaultPathSeparator)
&& Utils.PathIsDevicePath(parentPath)
&& parentPath.Length - parentPath.Replace(StringLiterals.DefaultPathSeparatorString, string.Empty).Length == 3)
{
// Device paths start with either "\\.\" or "\\?\"
// When referring to the root, like: "\\.\CDROM0\" then it needs the trailing separator to be valid.
parentPath += StringLiterals.DefaultPathSeparator;
}
#endif
return parentPath;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ Describe "Handling of globbing patterns" -Tags "CI" {
Test-Path -LiteralPath $testPath2 | Should -BeTrue
}
}

It "Handle wildcards in root of device path" -Skip:(!$IsWindows) {
MartinGC94 marked this conversation as resolved.
Show resolved Hide resolved
$Res = Get-ChildItem -Path '\\.\C:\*'
$Res.Count | Should -BeGreaterThan 0
}
}

Describe "Hard link and symbolic link tests" -Tags "CI", "RequireAdminOnWindows" {
Expand Down