fix(state): quote dotted terms in FTS5 queries - #4246
Closed
lumethegreat wants to merge 1 commit into
Closed
Conversation
FTS5 queries containing dots (e.g. P2.2, simulate.p2.test.ts) can trigger query parse edge cases that yield OperationalError or empty results unless quoted. Extend _sanitize_fts5_query to wrap dotted tokens in double quotes (similar to hyphenated terms) and add regression tests.
2 tasks
Contributor
|
Merged via PR #4549. Your commit was cherry-picked onto current main with your authorship preserved in git log. During salvage, I merged the dotted-term and hyphenated-term regex steps into a single pass to fix a double-quoting bug for terms containing both dots and hyphens (e.g. |
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.
What changed
FTS5 session search queries containing dots (e.g.
P2.2,simulate.p2.test.ts) can hit query parse edge cases that yield empty results (or anOperationalErrorthat gets handled as no matches) unless the term is quoted.This PR extends
SessionDB._sanitize_fts5_query()to automatically wrap dotted tokens in double quotes, similar to the existing mitigation for hyphenated terms.Why
Users naturally search for version-like strings (
P2.2) and file-like strings (simulate.p2.test.ts). Without quoting, these queries can be interpreted in ways that prevent matching, leading to misleading “no results” behavior insession_search.How it works
P2.2→"P2.2"simulate.p2.test.ts→"simulate.p2.test.ts"Tests
_sanitize_fts5_queryCommand:
pytest -q tests/test_hermes_state.py -k dottedFiles changed
hermes_state.pytests/test_hermes_state.py