fix(query-language): don't treat dash before a non-prefix colon word as negation#1301
fix(query-language): don't treat dash before a non-prefix colon word as negation#1301devteamaegis wants to merge 1 commit into
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.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (2)
WalkthroughThe PR refactors negation token recognition to rely on prefix keyword matching instead of colon-position scanning. The ChangesNegation Tokenization Refactor
🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 |
295e6a6 to
e353251
Compare
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