Repository navigation
fix(query): a ", \ or [[...]] in a title no longer breaks the query; a malformed query gets a query error - #13617
Closed
yuxi-liu-wired wants to merge 4 commits into
Closed
yuxi-liu-wired wants to merge 4 commits into
yuxi-liu-wired wants to merge 4 commits into
Conversation
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 6, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 6, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 8, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 8, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 11, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 11, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 13, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 13, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 16, 2026
yuxi-liu-wired
added a commit
to yuxi-liu-wired/logseq
that referenced
this pull request
Oct 16, 2026
yuxi-liu-wired
force-pushed
the
fix/query-tag-title-quote
branch
from
October 16, 2026 18:34
453d158 to
46df96f
Compare
yuxi-liu-wired
force-pushed
the
fix/query-tag-title-quote
branch
5 times, most recently
from
October 24, 2026 11:01
e331d11 to
461858a
Compare
yuxi-liu-wired
force-pushed
the
fix/query-tag-title-quote
branch
from
October 25, 2026 11:01
461858a to
44876ab
Compare
pre-transform quoted [[title]] as an EDN string without escaping it, so a tag renamed to Project" broke every (tags [[...]]) query on it with a reader error (db-test logseq#1374). The title is now escaped; the string match that protects # inside strings skips escaped quotes.
The page-ref match \[\[(.*?)\]\] stopped at the first ]], so a tag renamed to Project[[Gremlin Garden]] broke its queries (db-test logseq#1374). Refs are now found by a scan that counts [[ / ]] pairs, outside strings.
A malformed simple query failed deep in build-query or datascript with a raw error (alpha is not ISeqable, Insufficient bindings, ...). parse now validates the read form against a malli schema of the query grammar and throws one "Invalid query: ..." error naming the bad form or operator. Raw datalog clauses are no longer part of the simple query grammar, so build-query drops its datalog-clause? branch. pre-transform now matches an empty "" as a string, so a # after one is read as a tag.
…table query-operators now holds each operator's argument schema, error message, build fn and whether it queries blocks. build-query dispatches through it instead of a cond per operator, and query-schema is built from it, so the operators are listed once. The file-graph operators that build-query never translated in DB graphs (page-tags, page-ref, page-property, namespace, sort-by, full-text-search, all-page-tags) are now rejected instead of silently returning nothing.
yuxi-liu-wired
force-pushed
the
fix/query-tag-title-quote
branch
from
October 26, 2026 11:00
44876ab to
73893e2
Compare
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.
Fixes logseq/db-test#1374.
A
",\or[[...]]in a page or tag titleA tag
Project, a query{{query (tags [[Project]])}}, then the tag renamed toProject"on its page. The query, never edited, shows "Query error" with(tags [[Project"]]), and the worker logsUnmatched delimiter ].. A title with a\givesUnsupported escape character, one with"#...givesNo reader function for tag, and one with a[[...]]inside, such asProject[[Gremlin Garden]], is cut at the first]].pre-transformindeps/db/src/logseq/db/frontend/query_dsl.cljsturns each[[page]]of the query into an EDN string,"[[page]]":"in the title ended the string early and a\started an escape. The title is now escaped (\and") before it is quoted.\[\[(.*?)\]\], which stops at the first]]. Refs are now found by a scan that counts[[/]]pairs, so a nested pair stays inside the title; strings in the query are still copied through untouched, escapes included.#inside strings, matched strings with"[^"]+"; it now skips escaped quotes.The test
tags-query-with-a-quote-or-backslash-in-the-tag-titleinsrc/test/frontend/db/query_dsl_test.cljscovers this: 4 tags renamed toProject",back\slash,say "#hi"andProject[[Gremlin Garden]], each found by(tags [[...]]). It also checks thepre-transformoutput for an escaped title, for a nested pair, and for a[[...]]inside a string, which is left as it was. On master it fails with the reader errors above; with the change it passes.A malformed query gets a query error
A simple query with a malformed form failed deep inside
build-queryor datascript with a raw error such asalpha is not ISeqable,Insufficient bindingsorAll clauses in 'or' must use same set of free vars.parsenow checks the read form against a malli schema of the query grammar before translating it, and a bad query throws oneex-infobuilt from the malli explanation:Invalid query: alpha is not a query formInvalid query: between needs two dates, or created-at or updated-at and one or two datesquery-operatorsinfrontend.worker.query-dslis now the one list of operators: each entry holds the operator's argument schema, its error message, itsbuild-*fn, and whether it queries blocks.build-querydispatches through the table instead of acondbranch per operator, andquery-schemais built from it. Operators:and,or,not,task/todo,priority,tags,page,property,private-property,between,sample. A string is a[[page]]ref or a full-text search.Behavior changes, for review:
build-querynever translated in DB graphs (page-tags,page-ref,page-property,namespace,sort-by,full-text-search,all-page-tags) returned nothing silently. They are now rejected as "not a query form".[?b ...],[(pred ...)],((...))) are not part of the grammar.pre-transformtreats an empty""as a string. Before, a#tagafter one was left unexpanded and the reader threwNo reader function for tag ....Tests:
invalid-queriesruns the reported queries (alpha,TODO,(and todo [[A]]),[(or)],(not [((page-tags #nope))]),(between [[A]] B),(and (and 3.14) "x"),(or ((task)) "x"),(between (page "") (sample (priority #nope "alpha")))) plus(sort-by created-at), and checks each message;pre-transform-testhas a case for""followed by a tag.frontend.db.query-dsl-test: 27 tests, 125 assertions, 0 failures. The namespaces that run DSL queries (query-api, datalog, db-core, render-resource, db-worker,logseq.api.db) pass. clj-kondo and the large-vars lint are clean.