Skip to content

Stop regex ByWordAll matching blank text - #109

Merged
matt-edmondson merged 2 commits into
mainfrom
fix/regex-bywordall-empty-text-107
Sep 26, 2026
Merged

matt-edmondson merged 2 commits into
mainfrom
fix/regex-bywordall-empty-text-107

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #107

What was wrong

ExtractTextTokens returns an empty set for "" or " " under the word match options. The regex ByWordAll path then ran Enumerable.All over that set, and All on an empty sequence is true. As a result, blank text matched every regex pattern, so blank entries stayed visible in a list whatever the user typed. The glob path returns false for the same input.

Change

DoesMatchRegex now returns false when the text has no words, before it picks Any or All. This is the option the issue and the triage both recommend, and it matches the glob path. ByWordAny already returned false in this case, and ByWholeString never produces an empty set, so neither changes.

Tests

  • ByWordAllDoesNotMatchTextWithNoWords runs IsMatch and Filter over "" and " " for both filter types, which ties the two paths together.
  • RegexByWordAllFilterDropsBlankEntries covers the Filter(["", "hello"], "zzz", ...) case from the issue. It also checks that a matching word is still kept.

With the TextFilter.cs change reverted, the 3 regex cases fail. The glob cases pass either way, which is expected since they guard against regressions. With the fix, the full suite passes: 94 of 94 (dotnet test TextFilter.Test -c Release).

This PR is independent of #108 (#106). Both change TextFilter.cs, in separate methods.

🤖 Generated with Claude Code

https://claude.ai/code/session_01QPAgvLThqmty1U7AaebQMQ


Generated by Claude Code

ExtractTextTokens returns no words for "" or "   ", and Enumerable.All
over an empty set is true, so the regex ByWordAll path reported blank
text as matching every pattern while the glob path said no. The regex
path now returns false when the text has no words.

Fixes #107

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

# Conflicts:
#	TextFilter.Test/TextFilterTests.cs
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit c84ba84 into main Sep 26, 2026
12 checks passed
@matt-edmondson
matt-edmondson deleted the fix/regex-bywordall-empty-text-107 branch September 26, 2026 09:51
matt-edmondson added a commit that referenced this pull request Sep 26, 2026
Resolve the conflict in TextFilterTests.cs by keeping both the excluded
half-typed glob tests from this branch and the ByWordAll blank-text tests
from #109.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CZB6C9rAp2hA5WQDcw2NDp
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.

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

2 participants