You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Glob class [^a] is read as "a or ^", not as negation: x[^a] matches "xa" and "x^" but not "xb" #158
In bash, zsh, gitignore and minimatch, a character class that opens with ^ is negated, the same as [!...]. Regex uses ^ for negation too, and the filter box offers both glob and regex. DotNet.Glob doesn't treat ^ as negation, and TextFilter doesn't rewrite it before parsing. As a result [^a] turns into a positive class with two members, ^ and a. The user gets back exactly the items they meant to exclude, and nothing tells them so.
^ already means negation elsewhere in this filter syntax: a leading ^ marks an excluded token (ExcludedTokenPrefixes, TextFilter/TextFilter.cs:83). That makes it all the more surprising that ^ doesn't negate inside a class.
Reproduction
Tested on main @ 3b3784e with .NET 10, using TextFilter.IsMatch(text, filter) with the defaults (Glob, ByWordAny, CaseSensitive):
Filter
Text
Result
Expected
x[^a]
xb
False
True
x[^a]
xa
True
False
x[^a]
x^
True
False
x[!a]
xb
True
True
Suggested fix
MoveTrailingClassDashes (TextFilter/TextFilter.cs:474-518) already walks every closed class. It also recognises a leading ! (lines 492-493). Give a leading ^ the same treatment and emit ! in its place, so that [^a] becomes [!a] and [^a-] becomes [!-a]. Leave an unclosed class untouched, as happens today.
Open PR #156 reworks class handling and doesn't touch this. This fix should either land after that PR or be folded into it.
Acceptance criteria
IsMatch("xb", "x[^a]") returns true.
IsMatch("xa", "x[^a]") and IsMatch("x^", "x[^a]") return false.
[^a-] behaves like [!a-].
A ^ in any position other than first in a class is still a literal: x[a^] matches x^.
The behaviour is the same under CaseInsensitive.
The Glob hint or the README mentions both [!...] and [^...].
Priority: Medium. Results are silently inverted: x[^a] returns exactly what the user meant to exclude. [^...] is the common negation spelling in shells, gitignore and regex, so users will hit this. It only affects glob character classes, though, and the documented [!...] form works.
Activity
matt-edmondson commentedon Oct 29, 2026
Triage
x[^a]returns exactly what the user meant to exclude.[^...]is the common negation spelling in shells, gitignore and regex, so users will hit this. It only affects glob character classes, though, and the documented[!...]form works.TextFilter/TextFilter.cs.MoveTrailingClassDashesalready recognises a leading!. The owner of the glob class translation work (Glob character classes that combine a range with anything else silently drop members: [0-9a-f] doesn't match "c", [a-zA-Z] doesn't match "Q", [a-z_] doesn't match "_" #152, Since the trailing-dash fix (6937eb9), [a-z-] no longer matches "q", file[0-9a-] no longer matches "file5", and []a-] matches nothing #153, Glob class range spanning / or \ doesn't match it, and the negated class does:[.-0]misses "/",[!A-z]matches "\" #157) should take it.^. Land this after Match every member of a glob class that mixes a range with other characters [patch] #156 or fold it into it, as the issue suggests. Glob class range spanning / or \ doesn't match it, and the negated class does:[.-0]misses "/",[!A-z]matches "\" #157 is in the same code path and is worth fixing alongside.^in a closed class to!in the same pass that handles!, and leave unclosed classes untouched.x[a^]staying literal and the CaseInsensitive case.[!...]and[^...]in the hint or README.Generated by Claude Code
Move the #157 tests away from the lines #158's tests add to
Move the #172 tests away from the lines #158's and #165's tests add to
Match a literal ] straight after a glob class [patch] (#177)