Skip to content

Comments

[release/10.0] Make case insensitive matches respect case insensitivity on the root.#123976

Closed
github-actions[bot] wants to merge 5 commits intorelease/10.0from
backport/pr-120159-to-release/10.0
Closed

[release/10.0] Make case insensitive matches respect case insensitivity on the root.#123976
github-actions[bot] wants to merge 5 commits intorelease/10.0from
backport/pr-120159-to-release/10.0

Conversation

@github-actions
Copy link
Contributor

@github-actions github-actions bot commented Feb 3, 2026

Backport of #120159 to release/10.0

/cc @jozkee @MitchBodmer

Customer Impact

  • Customer reported
  • Found internally

Fixes: Matcher does not respect case insensitivity in root when using an InMemoryDirectoryInfo. (#119117)

Matcher.Match does not use the specified comparison which causes unexpected mismatches. This issue has a workaround but it's a filtering bug that can cause fewer matches to be returned than could actually exist on a filesystem, without the customer being able to detect this. This could be leading to data loss, corruption, or other behavioral bugs for customers.

// File is under "CASING1" but rootDir is "casing1"
var file = @"C:\root\CASING1\file.txt";

// Case-insensitive: matches despite casing difference
var caseInsensitive = new Matcher(StringComparison.OrdinalIgnoreCase);
caseInsensitive.AddInclude("*");
Console.WriteLine(caseInsensitive.Match(@"C:\root\casing1\", [file]).HasMatches); // True

// Case-sensitive: no match due to casing difference
var caseSensitive = new Matcher(StringComparison.Ordinal);
caseSensitive.AddInclude("*");
Console.WriteLine(caseSensitive.Match(@"C:\root\casing1\", [file]).HasMatches); // False

Before this fix, both matchers would return false because IsRootDirectory always used StringComparison.Ordinal regardless of the configured comparison type.

Regression

  • Yes
  • No

Testing

Change included new tests and the fix was verified by the customer.

Risk

Medium

This is technically a behavior change, but we believe it is very unlikely that there are customers relying on this bug since it results in fewer matches than what actually exist.

@MitchBodmer (the customer who reported, fixed, and validated this issue) shared the following analysis that @jozkee and @jeffhandley agree with:

  • If you're already working around this then a change here shouldn't cause an issue. You are already making the root case insensitive, and now you are doing so unnecessarily, but benignly.
  • If you are trying to make your search case sensitive, then you already have the desired behavior defined explicitly in your code. It would continue to be case sensitive, and nothing would change.
  • If you're not working around this because you are unaware of it then you are potentially missing files you intend to find, so fixing this would fix your code. That is good.

The only scenario I can imagine where fixing this would break any existing code would be in a place where you are intentionally matching case sensitively on the root and case inventively on the paths and pattern. That should effectively never be what you want.

Fix has been sitting in .NET 11 since September 2025.

@jozkee
Copy link
Member

jozkee commented Feb 4, 2026

/ba-g known test errors only.

@jozkee jozkee requested a review from a team February 4, 2026 17:38
@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Feb 6, 2026
@jeffhandley jeffhandley added area-System.IO Servicing-consider Issue for next servicing release review and removed needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners labels Feb 9, 2026
@dotnet-policy-service
Copy link
Contributor

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

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Backport fix for Microsoft.Extensions.FileSystemGlobbing.Matcher.Match (in-memory matching) so that root-directory matching respects the Matcher’s configured StringComparison, eliminating unexpected root mismatches when using case-insensitive matchers.

Changes:

  • Plumb the Matcher comparison setting into InMemoryDirectoryInfo via an internal Matcher.ComparisonType property.
  • Update InMemoryDirectoryInfo root matching to use the provided comparison rather than always using StringComparison.Ordinal.
  • Add functional tests covering case-insensitive root matches and case-sensitive root misses for in-memory matching.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
src/libraries/Microsoft.Extensions.FileSystemGlobbing/tests/FunctionalTests.cs Adds regression tests validating root-case behavior for in-memory matching under both case-sensitive and case-insensitive configurations.
src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/MatcherExtensions.cs Passes the Matcher’s configured comparison into InMemoryDirectoryInfo when matching in-memory file lists.
src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/Matcher.cs Exposes the configured StringComparison as an internal property for use by extension methods.
src/libraries/Microsoft.Extensions.FileSystemGlobbing/src/InMemoryDirectoryInfo.cs Stores the comparison type and uses it for root directory prefix matching (fixing the bug).

@jozkee
Copy link
Member

jozkee commented Feb 19, 2026

As some expressed offline, this has the risk of being a behavior change, even though it's fixing a bug, hence not suitable for backport. Our suggestion is to setup a workaround like root normalization for in-memory files. Additionally, if possible, I suggest detailing the bug to your code review agent until the fix ships in .NET 11. Closing.

@jozkee jozkee closed this Feb 19, 2026
@jozkee jozkee deleted the backport/pr-120159-to-release/10.0 branch February 19, 2026 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-System.IO Servicing-consider Issue for next servicing release review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants