fix(search): empty text/subject terms must not match every message#407
Merged
Conversation
Two related cases where an empty term produced LIKE '%%' (matches all) instead of the intended zero/no-op: - LIKE fallback path (ftsAvailable=false, reached when FTS errors at runtime or the binary is built without the fts5 tag): a tokenless TextTerm (empty or punctuation-only) was turned into LIKE '%term%'. For "" this matched every message. Skip tokenless terms (hasFTSToken, the same predicate the FTS path uses) and substitute FALSE when none remain, mirroring the FTS path. - subject: operator: the parser appended the raw value, so `subject:` or `subject:""` yielded SubjectTerms=[""] -> LIKE '%%' -> every message. Drop empty/whitespace values in the parser (mirroring the label handlers) and guard empty subject terms in the store. Punctuation-only values like subject:"!!!" remain valid literal substring searches. Adds an internal store test that forces the no-FTS branch (runs under the fts5 build too) and parser cases for empty/punctuation subject values. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012Ri7QdvXXUMQPke9wrLjSS
roborev: Combined Review (
|
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
An empty search term produced
LIKE '%%', which matched every message instead of nothing. Two cases:fts5tag): a tokenless term (empty or punctuation-only) becameLIKE '%term%';""matched everything. Tokenless terms are now skipped (same predicate the FTS path uses), substitutingFALSEwhen none remain — so the fallback mirrors the FTS path.subject:operator:subject:orsubject:""yielded an empty subject filter that matched every message. The parser now drops empty/whitespacesubject:values (mirroring the existinglabel:handlers);subject:"!!!"remains a valid literal substring search.🤖 Generated with Claude Code