Skip to content

fix(query): a plain-text query with a backslash searches instead of showing a query error - #13863

Closed
yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/query-result-reader-error
Closed

yuxi-liu-wired wants to merge 1 commit into
logseq:masterfrom
yuxi-liu-wired:fix/query-result-reader-error

Conversation

@yuxi-liu-wired

@yuxi-liu-wired yuxi-liu-wired commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

What the user sees

A plain-text query such as {{query foo\cbar}} (any text with a backslash escape the EDN reader rejects, e.g. \c, or a trailing \) shows a "Query error:" box with Unsupported escape character: \c. instead of running a full-text search for foo\cbar. Plain text without a backslash runs the full-text search as expected.

Cause

The query builder's sanitize-q wraps plain text in double quotes, so foo\cbar reaches the worker as "foo\cbar", which marks it as a full-text search. The worker's quoted-query-text reads that string with safe-read-string, which returns nil when the reader rejects the escape. With nil, execute-query-spec treats the text as a DSL query and passes it to query-dsl/execute-query, whose cljs.reader/read-string throws the reader exception. The worker turns that into a per-resource query error, and the query's error boundary shows it.

Change

quoted-query-text in frontend.worker.handler.render-resource.query now falls back to the raw text between the quotes when the reader cannot read the quoted string, so the full-text search runs on the text as typed. Strings the reader can read are unchanged, and malformed DSL queries such as ((and) still report their query error through the existing error boundary.

Tests

quoted-full-text-query-with-unreadable-escape-searches-raw-text-test in src/test/frontend/worker/handler/render_resource_test.cljs renders a :query resource for "foo\cbar" with a stubbed search-blocks. It checks that the resource has no error, that the search received foo\cbar, and that the matching block is returned; it also checks that ((and) still reports a query error. The test fails without the change (the resource carries the Unsupported escape character error and no search runs) and passes with it.


Devin Review

A plain-text query such as {{query foo\cbar}} showed a "Query error:"
box with "Unsupported escape character: \c." instead of running a
full-text search for foo\cbar.

The query builder's sanitize-q wraps plain text in double quotes to mark
it as a full-text search. The worker's quoted-query-text read that
string with safe-read-string, which returns nil when the EDN reader
rejects an escape such as \c. The query then fell through to the DSL
parser, whose reader threw, and the worker reported a query error.

quoted-query-text now falls back to the raw text between the quotes when
the reader cannot read the quoted string. Readable strings are
unchanged, and malformed DSL queries such as ((and) still report their
query error.

Test: quoted-full-text-query-with-unreadable-escape-searches-raw-text-test
checks that a "foo\cbar" query resource has no error, searches for
foo\cbar and returns the matching block, and that ((and) still reports
a query error. It fails without the change and passes with it.

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 potential issue.

Devin Review

Comment on lines +2919 to +2923
(with-redefs [search-handler/search-blocks
(fn [_repo query-text _options]
(swap! calls conj query-text)
[{:block/uuid resource-block
:block/title "foo\\cbar"}])]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔍 Literal-backslash matching remains untested

The search-blocks stub returns a block regardless of the query. The test confirms dispatch but cannot verify that indexed search matches text containing a literal backslash.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

This change is in how the query text is read (quoted-query-text): the test checks that the raw text foo\cbar reaches the search, instead of the query falling through to the DSL reader and failing. How the full-text index matches that text is the search's own behaviour and unchanged here, which is why the test stubs search-blocks and checks what it is called with.

@yuxi-liu-wired

Copy link
Copy Markdown
Contributor Author

Combined into #13871 with the other PRs of this theme, to keep the number of open PRs down; the commits are unchanged there.

@yuxi-liu-wired
yuxi-liu-wired deleted the fix/query-result-reader-error branch November 17, 2026 02:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant