fix(web): unescape quoted keyword search terms

Closed
BR
2mo ago
+98-3

Fixes #1687

In keyword mode the parser stripped the outer quotes of a quoted term but kept the escapes, so "foo \"bar\"" searched for foo \"bar\" and the example from the syntax reference found nothing. Quoted terms and quoted content: values now have \x resolved to x before the substring query is built. Regex mode is unchanged, since the regex engine interprets the escapes itself.

How I verified it

New tests in packages/web/src/features/search/parser.test.ts:

  • On main (b4931510), 3 of them fail. For example pattern is foo \"bar\" where foo "bar" is expected.
  • With the fix, all 6 in the file pass. The regex-mode control test passes both times.
  • The whole web suite passes (147 files, 1507 tests), and eslint is clean on both files.

A reviewer can confirm it by searching "foo \"bar\"" against a file that contains foo "bar".

AI disclosure: an AI coding agent working for the breken-ai account found, fixed and tested this.

🤖 Generated with Claude Code


[!NOTE]
Low Risk
Localized search-parser change with tests; regex mode behavior is explicitly preserved.

Overview
Fixes keyword (substring) search so backslash escapes inside quoted strings are resolved before building the Zoekt pattern. Queries like "foo \"bar\"" and content:"say \"hi\"" now match literal foo "bar" instead of searching for the backslash characters. Regex mode is unchanged—escaped strings still pass through to the regex engine.

Implementation adds unescapeQuotedString (quotes, backslashes, and line breaks after \) for QuotedTerm nodes and quoted content: values only. Changelog updated; six parser tests cover escapes, Windows paths, and the regex control case.

Reviewed by Cursor Bugbot for commit 2426084b1ef8bb422f01302df388e2955f181d4e. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Fixes #1687. Keyword search now resolves backslash escapes in quoted terms and quoted content: values, so "foo \"bar\"" matches foo "bar" instead of the literal foo \"bar\".

  • Escaped quotes, backslashes, and line terminators are resolved; other backslashes stay literal.
  • Regex mode is unchanged; escapes are left for the regex engine to interpret.
  • Adds a changelog entry and parser tests covering quoted terms, content: values, and both modes.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed keyword search so escaped quotes and backslashes in quoted terms are interpreted correctly, including quoted content: values. Escaped carriage returns and line feeds are also converted to line breaks, while backslashes before other characters remain literal.
    • Preserved escape sequences in regex searches and left unquoted content: values unchanged.