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 issue in editor config filepath comparison #73033

Merged
merged 5 commits into from
Apr 18, 2024

Conversation

ToddGrun
Copy link
Contributor

This code previously just did a simple string.StartsWith to check if a file was in a folder. However, this would incorrectly return true for a case such as testing if c:\foo\test.txt was in folder c:\foo\test.

This code previously just did a simple string.StartsWith to check if a file was in a folder. However, this would incorrectly return true for a case such as testing if c:\foo\test.txt was in folder c:\foo\test.
@ToddGrun ToddGrun requested a review from a team as a code owner April 15, 2024 21:33
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Apr 15, 2024
@@ -325,6 +325,26 @@ static void freeKey(List<Section> sectionKey, ObjectPool<List<Section>> pool)
sectionKey.Clear();
pool.Free(sectionKey);
}

static bool isNormalizedPathInDirectory(string path, string directory)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we use helper PathUtilities.IsSameDirectoryOrChildOf instead?

Copy link
Contributor Author

@ToddGrun ToddGrun Apr 15, 2024

Choose a reason for hiding this comment

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

I actually didn't know that method existed. I can go either way, a couple thoughts:

  1. The change I made is simple, but the other method is probably fairly well tested
  2. PathUtilities.IsSameDirectoryOrChildOf appears to do quite a bit of allocation
  3. PathUtilities.IsSameDirectoryOrChildOf does an OrdinalIgnoreCase comparison whereas this code does an Ordinal comparison

Copy link
Contributor

Choose a reason for hiding this comment

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

I would push toward use of the existing helpers, if the task we need to perform appears to be the same. I feel these kinds of helpers are not easy to get right. I'm def open to review any optimization of existing helpers. I would prefer to avoid having multiple helpers for doing almost the same thing with paths across the codebase with subtle differences which we aren't sure are correct.

Copy link
Member

Choose a reason for hiding this comment

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

I agree with Rikki on this. FilePath stuff is tricky (i just broke it myself in the IDE). consolidating on helpers is the way to go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've gone ahead and used IsSameDirectoryOrChildOf per the suggestion above and modified it to take in casing behavior. I also saw IsChildPath, which looked significantly more performant, but used IsUnixLikePlatform to determine case sensitivity.

Copy link
Member

Choose a reason for hiding this comment

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

Note: orthogonal to your PR, case sensitivity cannot be determined by asking what platform you're on. It's dependent on the file system, which could be mounted into arbitrary hosts at a per path-segment level. For example /A/B/C/D might transition through 4 different file systems, on different hosts, with differing case-sensitivity behavior.

We likely have bugs here, which will hit users doing things like mounting win-directories into wsl, or vice versa.

@RikkiGibson RikkiGibson self-assigned this Apr 15, 2024
@jaredpar jaredpar added this to the 17.11 milestone Apr 16, 2024
@RikkiGibson
Copy link
Contributor

It looks like test IsSameDirectoryOrChildOfSpecifyingCaseSensitivity is still failing at least on Linux.

@ToddGrun
Copy link
Contributor Author

@RikkiGibson

It looks like test IsSameDirectoryOrChildOfSpecifyingCaseSensitivity is still failing at least on Linux.

Made unix/windows specific versions of the test. PTAL at your convenience. Thanks!

@ToddGrun ToddGrun merged commit 1bf2361 into dotnet:main Apr 18, 2024
24 checks passed
@dotnet-policy-service dotnet-policy-service bot modified the milestones: 17.11, Next Apr 18, 2024
@dibarbet dibarbet modified the milestones: Next, 17.11 P1 Apr 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants