Skip to content

Glob with ByWholeString requires every optional token to match, so "*.jpg *.png" matches nothing #113

Description

@matt-edmondson

What's wrong

DoesMatchGlob (TextFilter/TextFilter.cs ~344) picks the function that combines the optional tokens like this:

Func<...> optionalMatchFunc = textFilterMatchOptions is TextFilterMatchOptions.ByWordAny
	? Enumerable.Any
	: Enumerable.All;

That means ByWholeString also falls through to All. Under ByWholeString the text is a single token, so a filter with two or more optional alternatives matches only text that satisfies every alternative at once. For extension globs, no text can do that.

This contradicts the documented contract. GetHint(TextFilterType.Glob) says the "text must contain one of the optional tokens, all of the required tokens, and none of the excluded tokens". It also disagrees with ByWordAny on the same single-word text, which returns true.

Repro (reproduced)

TextFilter.IsMatch("photo.jpg", "*.jpg *.png", TextFilterType.Glob, TextFilterMatchOptions.ByWholeString); // False
TextFilter.IsMatch("photo.jpg", "*.jpg *.png", TextFilterType.Glob, TextFilterMatchOptions.ByWordAny);     // True
TextFilter.Filter(new[]{"a.jpg","b.png","c.txt"}, "*.jpg *.png", TextFilterType.Glob, TextFilterMatchOptions.ByWholeString); // empty
// Expected: True, and [a.jpg, b.png]

Why it matters

ByWholeString is the natural mode for filtering file names and paths. When a user types two alternatives into a filter box, the list is emptied silently, with no error.

Suggested fix

Use All only for ByWordAll, and Any otherwise:

textFilterMatchOptions is TextFilterMatchOptions.ByWordAll ? Enumerable.All : Enumerable.Any

Acceptance: a test pins ByWholeString with multiple optional tokens so that one matching alternative is enough.

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