fix(query-language): don't treat dash before a non-prefix colon word as negation - #1301
Merged
brendan-kellam merged 3 commits intoAug 5, 2026
Conversation
…d as negation A query like `-foo:bar` or `-http://example.com` raised a SyntaxError. The negate tokenizer accepted `-` as negation whenever any colon appeared in the following word, but the grammar only allows a NegateExpr to wrap a known PrefixExpr. With no matching prefix, the strict parser used in search failed the whole query. Now negation is only emitted when the dash is immediately followed by a known prefix keyword; other colon-bearing words parse as a single Term.
Contributor
WalkthroughThe PR changes negation token recognition to use known prefix matching instead of colon scanning. Tests cover non-prefix URLs, colon terms, and mixed expressions. The changelog records the parsing fix. ChangesNegation Tokenization Refactor
Estimated code review effort: 2 (Simple) | ~10 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
devteamaegis
force-pushed
the
fix/negate-non-prefix-colon-word
branch
from
June 11, 2026 19:45
295e6a6 to
e353251
Compare
Contributor
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Contributor
|
@claude add a brief Changelog entry |
This comment was marked as resolved.
This comment was marked as resolved.
brendan-kellam
approved these changes
Aug 5, 2026
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's broken
A search query that negates a bare word containing a colon crashes the parser, and
parseQuerySyntaxIntoIR(strict mode) turns that into a user-facingFAILED_TO_PARSE_QUERY400 — the whole search fails. Examples:-foo:bar,-http://example.com,-time:12. Notefoo:barwithout the dash parses fine; only the negated form breaks.Why it happens
The grammar only allows
NegateExpr { negate (PrefixExpr | ParenExpr) }, butnegateTokenemitted thenegatetoken whenever the following word contained any colon, not when it actually started with a known prefix keyword. So-foo:baremittednegateand then left a bare word with no PrefixExpr to attach to → no parse.Fix
Only emit
negatewhen the dash is immediately followed by a known prefix keyword, using the existingstartsWithPrefixAthelper. Bare words with colons fall through towordToken.Test
Added cases to
negation.txt:-http://example.com,-time:12, andrepo:x -foo:barnow parse as Terms; the existing-file:...prefix-negation cases still pass.Summary by CodeRabbit
Bug Fixes
Tests
Note
Low Risk
Localized query-language tokenizer change with regression tests; real prefix negation paths unchanged.
Overview
Fixes search parse failures when a query uses a leading dash on a bare term that contains a colon (e.g.
-foo:bar,-http://example.com). Those inputs previously triggered a strict-parserSyntaxErrorandFAILED_TO_PARSE_QUERYinstead of being treated as a single search term.Tokenizer change:
negateTokenno longer treats “dash + any word with a colon” as negation. It only emitsnegatewhen the dash is followed by a known prefix keyword (viastartsWithPrefixAt), matching real negation like-file:. Colon-bearing bare words are left towordTokenas oneTerm.Tests & changelog: New
negation.txtcases cover URLs, unknowntime:keys, and mixedrepo:x -foo:bar; changelog entry added.Reviewed by Cursor Bugbot for commit 95e7902. Bugbot is set up for automated code reviews on this repo. Configure here.