FileSystemGlobbing: Allow rootDir paths ending with separator to match files correctly#45139
Conversation
|
Tagging subscribers to this area: @maryamariyan Issue Details
|
There was a problem hiding this comment.
Existing condition on line 126 was meant to avoid false positives when the path started with rootDir but it wasn't the complete name of the directory e.g:
var matcher = new Matcher();
matcher.AddInclude(@"**\*");
Console.WriteLine(matcher.Match(rootDir: @"C:\foo", file: @"C:\foo2\bar.cs").HasMatches);
// prints false, which is correct.
However that same condition was interfering when rootDir = @"C:\foo\" since filePath.IndexOf(Path.DirectorySeparatorChar, rootDirLength) was always going to return the index of the separator of the next directory.
Therefore I added condition on line 125 in order to skip the length check when rootDir ends with a separator.
There was a problem hiding this comment.
It seems line 126 checks one char in position rootDirLength - why do we use whole IndexOf() method instead of simple index - filePath[rootDirLength] == Path.DirectorySeparatorChar - like in line 125?
c282838 to
855b266
Compare
src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/InMemoryDirectoryInfo.cs
Outdated
Show resolved
Hide resolved
src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FunctionalTests.cs
Outdated
Show resolved
Hide resolved
carlossanlop
left a comment
There was a problem hiding this comment.
LGTM. Left some minor comments.
|
Actually, I noticed all the unit test failures are happening in |
855b266 to
21a8093
Compare
|
@carlossanlop I excluded scenarios using Windows-like absolute paths from running on non-Windows OSes since FileSystemGlobbing is OS-dependent when dealing with paths. That should fix the issues on CI. |
InMemoryDirectoryInfo.IsRootDirectorymethod was failing to evaluate correctly when the rootDir argument was ending with a separator e.g:C:\or/. This PR changes the condition to correctly support the aforementioned cases.Fixes #36415, #44767