Skip to content

Commit

Permalink
Path.GetFullPath(string, string) uses case insensitive volume name co…
Browse files Browse the repository at this point in the history
…mparison for drive rooted, relative paths (#97759)

* check root for drive relative paths case insensitive.

* Remove link

* apply feedback

---------

Co-authored-by: David Cantú <dacantu@microsoft.com>
  • Loading branch information
AnakinRaW and Jozkee committed Mar 19, 2024
1 parent b9dfd37 commit 3209346
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static string GetFullPath(string path, string basePath)
// Drive relative paths
Debug.Assert(length == 2 || !PathInternal.IsDirectorySeparator(path[2]));

if (GetVolumeName(path.AsSpan()).EqualsOrdinal(GetVolumeName(basePath.AsSpan())))
if (GetVolumeName(path.AsSpan()).EqualsOrdinalIgnoreCase(GetVolumeName(basePath.AsSpan())))
{
// Matching root
// "C:Foo" and "C:\Bar" => "C:\Bar\Foo"
Expand Down Expand Up @@ -349,8 +349,8 @@ internal static int GetUncRootLength(ReadOnlySpan<char> path)
if (!isDevice && path.Slice(0, 2).EqualsOrdinal(@"\\".AsSpan()))
return 2;
else if (isDevice && path.Length >= 8
&& (path.Slice(0, 8).EqualsOrdinal(PathInternal.UncExtendedPathPrefix.AsSpan())
|| path.Slice(5, 4).EqualsOrdinal(@"UNC\".AsSpan())))
&& (path.Slice(0, 8).EqualsOrdinalIgnoreCase(PathInternal.UncExtendedPathPrefix.AsSpan())
|| path.Slice(5, 4).EqualsOrdinalIgnoreCase(@"UNC\".AsSpan())))
return 8;

return -1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,8 @@ public void GetFullPath_CommonDevice_Windows(string path, string basePath, strin
{ @"C:tmp", @"C:\git\runtime", @"C:\git\runtime\tmp" },
{ @"C:", @"C:\git\runtime", @"C:\git\runtime" },
{ @"C", @"C:\git\runtime", @"C:\git\runtime\C" },
{ @"c:", @"C:\git\runtime", @"C:\git\runtime" },
{ @"C:tmp", @"c:\git\runtime", @"c:\git\runtime\tmp" },

{ @"Z:tmp\foo\..", @"C:\git\runtime", @"Z:\tmp" },
{ @"Z:tmp\foo\.", @"C:\git\runtime", @"Z:\tmp\foo" },
Expand Down

0 comments on commit 3209346

Please sign in to comment.