Skip to content

Match every member of a glob class that mixes a range with other characters [patch] - #156

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/152-153-glob-class-ranges
Oct 30, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/152-153-glob-class-ranges

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #152
Fixes #153

What was wrong

DotNet.Glob 3.1.3 reads a bracket class as one token: a single range when the class starts x-y with two letters or two digits, or otherwise a plain character list where - is a member and no ranges are read. It never combines them, so:

The fix

MoveTrailingClassDashes is replaced by ExpandGlobClasses. It rewrites every closed class DotNet.Glob would misread into the explicit character list it means, using the usual glob rules: a leading ] and a leading or trailing - are literal, and x-y is an inclusive range. Negation is kept. The list is written in an order DotNet.Glob reads as a plain list: ] first, then -, and ! never first. So [0-9a-f] becomes [0123456789abcdef], [a-z-] becomes [-abc…z], and []a-] becomes []-a].

  • A lone letter or digit range ([a-z], [!0-9], [一-龥]) is left for DotNet.Glob to match natively. It already reads that form correctly, and it may cover far more characters than are worth listing.
  • A class with no - is left unchanged.
  • A class whose ranges cover more than 4096 characters, or that ends up with no members because every range is reversed, is treated as unparseable. It takes the existing ignored-token path, which is the same thing that happens to a half-typed file[0-.

I verified the list and range behaviour against DotNet.Glob 3.1.3 directly before writing the ordering rules.

Tests

  • The rewrite assertions that only checked text are now ExpandGlobClassesRewritesOnlyClassesDotNetGlobMisreads and ExpandGlobClassesRejectsClassesThatCannotBeListed.
  • New match assertions run through IsMatch (Glob, ByWholeString), each case-sensitive and case-insensitive. They cover [0-9a-f], [!0-9a-f], [a-z_], [-0-9], [ab-d], [a-z-], file[0-9a-], []a-], [!]a-], [!-#], and [a-zA-Z] matching both cases.
  • 20 of the new or changed cases fail on main's implementation and all pass with this change. The full suite passes: 189/189.

Generated by Claude Code

…acters [patch]

DotNet.Glob reads a bracket class as a single range or a plain character
list, never both, so [0-9a-f] missed "c", [a-zA-Z] missed "Q" and [a-z_]
missed "_". Moving a trailing dash to the front (6937eb9) also pushed
classes it read correctly, such as [a-z-] and file[0-9a-], into list mode,
and turned []a-] into a pattern that matched nothing.

Each closed class DotNet.Glob would misread is now rewritten into the
explicit character list it means, keeping negation, with "]" first, "-"
next and "!" never first. A lone letter or digit range is left for
DotNet.Glob to match natively. A class whose ranges span more than 4096
characters, or that has no members, is treated as unparseable.

Fixes #152
Fixes #153

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4bHjeyXzXRGQc26aV
…ognitive complexity

Addresses SonarCloud S3776 on ExpandGlobClasses (18 against a limit of 15).
No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW4bHjeyXzXRGQc26aV
@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

2 participants