Skip to content

Regex + ByWordAll matches empty or whitespace-only text against any pattern #107

Description

@matt-edmondson

What's wrong

In the regex ByWordAll path (TextFilter/TextFilter.cs:~460-464), ExtractTextTokens returns an empty set for "" or " ". The check then runs Enumerable.All over that set, and All on an empty sequence is true. So text with no words is reported as matching every pattern. The glob path returns false for the same input.

Failure scenario (verified with a temporary MSTest)

IsMatch("",    "zzz", TextFilterType.Regex, TextFilterMatchOptions.ByWordAll); // true
IsMatch("   ", "zzz", TextFilterType.Regex, TextFilterMatchOptions.ByWordAll); // true
IsMatch("",    "zzz", TextFilterType.Glob,  TextFilterMatchOptions.ByWordAll); // false
Filter(["", "hello"], "zzz", TextFilterType.Regex, TextFilterMatchOptions.ByWordAll); // [""]

In a list UI, blank entries stay visible whatever the user types. The two filter types also disagree on the same input.

Suggested fix

In the regex ByWordAll branch, return false when textTokens.Count == 0, which matches the glob path. Alternatively, fall back to matching the whole string.

Acceptance: all four calls above return false, or [] for Filter, and a test covers both filter types.

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