Skip to content

Glob filter throws IndexOutOfRangeException on half-typed ranges like "file[0-", crashing type-ahead filters #106

Description

@matt-edmondson

What's wrong

ResolveGlob (TextFilter/TextFilter.cs:~399-408) calls Glob.Parse with no exception handling. DotNet.Glob's tokenizer (GlobTokeniser.ReadRangeOrListToken) throws IndexOutOfRangeException when a range is left open after the dash. That exception escapes from IsMatch and Filter.

The regex path doesn't behave this way: it turns an invalid pattern into match-anything. The glob path has no equivalent fallback.

Failure scenario (verified with a temporary MSTest)

Take a filter box that re-filters on each keystroke. While the user is typing file[0-9].txt, the intermediate text file[0- reaches this call:

TextFilter.Filter(["file1.txt"], "file[0-");   // IndexOutOfRangeException

Patterns that throw:

  • [a-
  • a[b-
  • [!a-
  • *[0-
  • [a-]

Other malformed patterns don't throw; they just return false: [a-z, [, [!, {, [], a\.

Suggested fix

Wrap Glob.Parse in ResolveGlob in a try/catch. On failure, degrade the same way the regex path does:

  • cache a match-anything glob (*), or a glob that treats the token literally;
  • keep the cache bounded, as it is now.

It may also be worth reporting the tokenizer crash upstream to DotNet.Glob.

Acceptance: IsMatch and Filter never throw for any of the patterns listed above, and a test pins down that behaviour.

Activity

  1. matt-edmondson commented on Sep 26, 2026

    @matt-edmondson
    ContributorAuthor

    Triage

    • Category: Bug
    • Priority: Medium. An unhandled exception escapes IsMatch/Filter on ordinary intermediate input while someone types a range. Type-ahead filter UIs are this library's main use case, so consumers without their own try/catch crash.
    • Area: TextFilter.ResolveGlob (DotNet.Glob parse)
    • Suggested assignment: TextFilter maintainer
    • Duplicates: None. Related to Regex + ByWordAll matches empty or whitespace-only text against any pattern #107 (same file, regex ByWordAll), so the two could share a PR. GitLfsCache Bump Polyfill from 10.8.0 to 10.8.1 #33 plans to delegate glob matching to ktsu.TextFilter, so this fix should land before that work.
    • In progress: No open PR covers this.

    Notes: Of the two fallbacks, match-anything is consistent with the regex path. A literal-token fallback is arguably more intuitive while typing file[0-. Pick one and document it. Catch broadly (Exception, not just IndexOutOfRangeException) so the next tokenizer bug is contained too. The upstream DotNet.Glob report is worth filing.


    Generated by Claude Code

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

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions