Repository navigation
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
Closed
yuxi-liu-wired wants to merge 1 commit into
yuxi-liu-wired wants to merge 1 commit into
Conversation
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.
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"}])] |
Contributor
There was a problem hiding this comment.
Contributor
Author
|
This change is in how the query text is read ( |
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. |
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 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 withUnsupported escape character: \c.instead of running a full-text search forfoo\cbar. Plain text without a backslash runs the full-text search as expected.Cause
The query builder's
sanitize-qwraps plain text in double quotes, sofoo\cbarreaches the worker as"foo\cbar", which marks it as a full-text search. The worker'squoted-query-textreads that string withsafe-read-string, which returns nil when the reader rejects the escape. With nil,execute-query-spectreats the text as a DSL query and passes it toquery-dsl/execute-query, whosecljs.reader/read-stringthrows the reader exception. The worker turns that into a per-resource query error, and the query's error boundary shows it.Change
quoted-query-textinfrontend.worker.handler.render-resource.querynow 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-testinsrc/test/frontend/worker/handler/render_resource_test.cljsrenders a:queryresource for"foo\cbar"with a stubbedsearch-blocks. It checks that the resource has no error, that the search receivedfoo\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 theUnsupported escape charactererror and no search runs) and passes with it.