Skip to content

fix(query-language): don't treat dash before a non-prefix colon word as negation - #1301

Merged
brendan-kellam merged 3 commits into
sourcebot-dev:mainfrom
devteamaegis:fix/negate-non-prefix-colon-word
Aug 5, 2026
Merged

fix(query-language): don't treat dash before a non-prefix colon word as negation#1301
brendan-kellam merged 3 commits into
sourcebot-dev:mainfrom
devteamaegis:fix/negate-non-prefix-colon-word

Conversation

@devteamaegis

@devteamaegis devteamaegis commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

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-facing FAILED_TO_PARSE_QUERY 400 — the whole search fails. Examples: -foo:bar, -http://example.com, -time:12. Note foo:bar without the dash parses fine; only the negated form breaks.

"-foo:bar"            => SyntaxError: No parse at 1
"-http://example.com" => SyntaxError: No parse at 1
"-file:bar"           => OK   (real prefix negation still works)

Why it happens

The grammar only allows NegateExpr { negate (PrefixExpr | ParenExpr) }, but negateToken emitted the negate token whenever the following word contained any colon, not when it actually started with a known prefix keyword. So -foo:bar emitted negate and then left a bare word with no PrefixExpr to attach to → no parse.

Fix

Only emit negate when the dash is immediately followed by a known prefix keyword, using the existing startsWithPrefixAt helper. Bare words with colons fall through to wordToken.

Test

Added cases to negation.txt: -http://example.com, -time:12, and repo:x -foo:bar now parse as Terms; the existing -file:... prefix-negation cases still pass.

Summary by CodeRabbit

  • Bug Fixes

    • Query parsing now correctly handles dash-prefixed terms containing colons, including URLs, without incorrectly interpreting them as negated prefixes.
  • Tests

    • Added coverage for colon-containing terms and mixed prefix-and-term expressions to ensure accurate parsing.

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-parser SyntaxError and FAILED_TO_PARSE_QUERY instead of being treated as a single search term.

Tokenizer change: negateToken no longer treats “dash + any word with a colon” as negation. It only emits negate when the dash is followed by a known prefix keyword (via startsWithPrefixAt), matching real negation like -file:. Colon-bearing bare words are left to wordToken as one Term.

Tests & changelog: New negation.txt cases cover URLs, unknown time: keys, and mixed repo: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.

…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.
@coderabbitai

coderabbitai Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The 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.

Changes

Negation Tokenization Refactor

Layer / File(s) Summary
Negation token logic update
packages/queryLanguage/src/tokens.ts
negateToken now uses startsWithPrefixAt(input, offset). Dash-prefixed text without a known prefix remains available to wordToken.
Negation test validation and changelog
packages/queryLanguage/test/negation.txt, CHANGELOG.md
Added tests for -http://example.com, -time:12, and repo:x -foo:bar. Added an Unreleased changelog entry for the parsing fix.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested reviewers: brendan-kellam

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the parser fix for dash-prefixed colon terms that are not known prefixes.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@devteamaegis
devteamaegis force-pushed the fix/negate-non-prefix-colon-word branch from 295e6a6 to e353251 Compare June 11, 2026 19:45
@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
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.

@brendan-kellam

Copy link
Copy Markdown
Contributor

@claude add a brief Changelog entry

@claude

This comment was marked as resolved.

@brendan-kellam
brendan-kellam merged commit b4a1c06 into sourcebot-dev:main Aug 5, 2026
8 checks passed
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.

2 participants