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

Path.GetFullPath(string, string) uses case insensitive volume name comparison for drive rooted, relative paths #97759

Merged
merged 12 commits into from
Mar 19, 2024

Conversation

AnakinRaW
Copy link
Contributor

Fixes #97615 (if the case the current behavior should be changed)

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jan 31, 2024
@ghost
Copy link

ghost commented Jan 31, 2024

Tagging subscribers to this area: @dotnet/area-system-io
See info in area-owners.md if you want to be subscribed.

Issue Details

Fixes #97615 (if the case the current behavior should be changed)

Author: AnakinRaW
Assignees: -
Labels:

area-System.IO

Milestone: -

@AnakinRaW
Copy link
Contributor Author

@dotnet-policy-service agree

@adamsitnik
Copy link
Member

@AnakinRaW thank you for your contribution. The person who owns this code will be able to review the PR after 12th of March. I am sorry for the delay.

@@ -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())))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are other places in this file where EqualsOrdinal is used, can you change those as well?

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure. done that. However, I omitted EqualsOrdinal(@"\\".AsSpan() as there is nothing to compare case-insensitive. If it should be consistent though, i can chance again of course.

Copy link

@rhuijben rhuijben Mar 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is correct for \\SERVER\SHARE as I think this is a valid volume name on Windows.

In that case the server name should be case insensitive, but the share name might not (Think non windows OSs like Samba on linux).

Testcases on these paths are usually hard, as this call might try contacting the server...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GetVolumeName is only used when path is drive relative like C:foo, it's used to check whether path and basePath have the same root, the method is probably more complex than it needs to but I don't think it would affect UNC paths.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually that was my thought when applying the changes :)

Copy link
Member

@jozkee jozkee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.

@jozkee jozkee merged commit 3209346 into dotnet:main Mar 19, 2024
146 of 150 checks passed
@AnakinRaW AnakinRaW deleted the caseinsensitive-driverelative-path branch March 19, 2024 19:29
@github-actions github-actions bot locked and limited conversation to collaborators Apr 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.IO community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Question] Case sensitivity for GetFullPath(string, string) with drive relative paths
4 participants