Skip to content

Stop half-typed glob ranges from throwing - #108

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/glob-half-typed-range-106
Sep 26, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/glob-half-typed-range-106

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #106

What was wrong

ResolveGlob called Glob.Parse without catching anything. DotNet.Glob's tokeniser throws IndexOutOfRangeException when a range is left open after the dash, and that exception escaped IsMatch and Filter. A filter box that re-filters on each keystroke crashes at file[0- while the user types file[0-9].txt. The regex path doesn't have this problem, because it already turns an invalid pattern into match-anything.

Change

  • ResolveGlob now wraps the parse in a try/catch. On failure it caches a match-anything glob (*), so a bad pattern degrades the same way an invalid regex does and the exception isn't raised again on the next keystroke. The cache stays bounded as before.
  • The catch takes any exception except OutOfMemoryException, as triage suggested, so the next tokeniser bug is contained too.
  • The fallback is documented in the DoesMatchGlob remarks.

I chose match-anything over treating the token literally because it matches the regex path, and because the list doesn't flash empty while someone is halfway through typing a range.

Tests

GlobWithAHalfTypedRangeDoesNotThrow covers every throwing pattern listed in the issue (file[0-, [a-, a[b-, [!a-, *[0-, [a-]), through both IsMatch and Filter, at both case sensitivities.

  • With the TextFilter.cs change reverted, all 6 cases fail with System.IndexOutOfRangeException.
  • With the fix, the full suite passes: 95 of 95 (dotnet test TextFilter.Test -c Release).

I haven't filed the upstream DotNet.Glob report.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QPAgvLThqmty1U7AaebQMQ


Generated by Claude Code

DotNet.Glob's tokeniser throws IndexOutOfRangeException on a range left
open after the dash ("file[0-"), which escaped IsMatch and Filter while a
user typed a range into a filter box. ResolveGlob now catches the parse
failure and caches a match-anything glob, the same way an invalid regex
pattern already degrades.

Fixes #106

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

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit fdf6930 into main Sep 26, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/glob-half-typed-range-106 branch September 26, 2026 03:48
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 throws IndexOutOfRangeException on half-typed ranges like "file[0-", crashing type-ahead filters

2 participants