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

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