Skip to content

Mask / and \ to different characters in glob matching [patch] - #175

Open
matt-edmondson wants to merge 1 commit into
mainfrom
fix/132-distinct-separator-masks
Open

matt-edmondson wants to merge 1 commit into
mainfrom
fix/132-distinct-separator-masks

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #132

What was wrong

The #114 fix masks path separators so that DotNet.Glob treats them as ordinary characters. It masked both / and \ to U+E000, so after masking the glob could no longer tell them apart:

  • 1/2 matched 1\2.
  • -*/* hid C:\temp along with URLs.

Change

  • \ is now masked to U+E001, and / stays U+E000. The same masking applies to the pattern and the text.
  • ExpandGlobStarSegments used to look for ** followed by the single mask. It now accepts either mask, and when it keeps the *<sep> form, that form ends at the separator the pattern wrote.

Behaviour change: a ** segment no longer crosses into the other separator kind. src/**/*.cs doesn't match src\x\a.cs, and src\**\*.cs doesn't match src/x/a.cs. That follows from the issue's rule that the two characters are different. A single * or ? still crosses either separator, as #114 requires.

This edits ExpandGlobStarSegments, which open PR #171 also touches, so whichever lands second may need a small rebase.

Tests

  • GlobTellsSlashAndBackslashApart covers the issue's three cases in both directions, under both sensitivities. It also checks that * and ? still cross either separator.
  • GlobStarSegmentEndsAtTheSeparatorThePatternWrote covers the mixed-separator ** case above.
  • GlobClassRangeSpanningAPathSeparatorMatchesIt (Glob class range spanning / or \ doesn't match it, and the negated class does: [.-0] misses "/", [!A-z] matches "\" #157) now separates the two characters. Its comment said its rows couldn't, because of this issue. [*-0] previously listed \ as matching, which only held because of the shared mask: \ (0x5C) is outside *–0.
  • With \ masked back to U+E000, 9 tests fail. With the fix, the full suite passes on net10.0: 217/217.

Generated by Claude Code

Both separators were masked to U+E000, so after masking a glob could not
tell them apart: "1/2" also matched "1\2", and "-*/*" excluded Windows
paths along with URLs. "\" now masks to U+E001, and a "**" segment keeps
the separator the pattern wrote.

Fixes #132

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW2nwQnKNnZqSnbuUxe
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Glob filter 1/2 also matches 1\2, and excluding -*/* also hides C:\temp: / and \ are masked to the same character

1 participant