Repository navigation
fix: escape special characters in query-dsl page refs #13541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 1 commit
aadf85a
9f0ea0f
73d2806
56ccda2
52b19e1
caf574b
c83036f
9ccb478
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
Query DSL strings that reference pages by title (e.g. (tags [[Project"]])) break cljs.reader when a title contains special characters like " or \\. Instead of hardening the title-form reader path, keep page refs in their stored [[uuid]] form end to end: - execution reads :block/raw-title (the stored form) instead of the display-substituted :block/title (query-result, flashcards, query builder) - new query value blocks write [[uuid]] refs: pipeline tag-query sync, create-property-text-block!, and the file-graph exporter - dsl clauses resolve [[uuid]] args via get-page (tags/page/between/property) - display still shows titles via canonical-block's substituted :block/title - pre-transform keeps a simplified scanner for legacy title-form queries Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1388,14 +1388,30 @@ | |
| ast-blocks) | ||
| @results)) | ||
|
|
||
| (defn- query-refs->id-refs | ||
| "Replaces `[[title]]` refs in a query string with `[[uuid]]` for pages that | ||
| resolve in page-names-to-uuids" | ||
| [query page-names-to-uuids] | ||
| (if (string/includes? query "[[") | ||
| (let [ref-pages (keep (fn [[_ page-name]] | ||
| (when-let [id (or (get @page-names-to-uuids page-name) | ||
| (get @page-names-to-uuids | ||
| (common-util/page-name-sanity-lc page-name)))] | ||
| {:block/title page-name :block/uuid id})) | ||
| (re-seq page-ref/page-ref-re query))] | ||
| (if (seq ref-pages) | ||
| (db-content/title-ref->id-ref query ref-pages {:replace-tag? false}) | ||
|
Comment on lines
+1395
to
+1403
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🟡 Quoted query text changes during import When an imported query contains a quoted Learn moreThe importer now converts all regex-matched page references in simple, advanced, and cards query text to IDs. This includes matches inside quoted query strings. Quoted strings in DSL property or content searches, and string constants in advanced Datalog queries, can be literal text rather than page arguments. Replacing those strings changes the stored query's meaning. Example: An advanced query whose predicate compares a title against Recommended fix: Parse the query format and convert only syntactic page-reference operands, preserving quoted string literals. Add tests for quoted refs in advanced queries and literal-content searches. Was this helpful? React with 👍 or 👎 to provide feedback. |
||
| query)) | ||
| query)) | ||
|
|
||
| (defn- handle-queries | ||
| "If a block contains a simple or advanced queries, converts block to a #Query node. If a block | ||
| contains a cards query converts to a #Cards node" | ||
| [{:block/keys [title] :as block} db page-names-to-uuids walked-ast-blocks options] | ||
| (if-let [query (some-> (first (:simple-queries walked-ast-blocks)) | ||
| (ast->text (select-keys options [:log-fn])) | ||
| string/trim)] | ||
| (let [props {:logseq.property/query query} | ||
| (let [props {:logseq.property/query (query-refs->id-refs query page-names-to-uuids)} | ||
| {:keys [block-properties pvalues-tx]} | ||
| (build-properties-and-values props db page-names-to-uuids | ||
| (select-keys block [:block/properties-text-values :block/name :block/title :block/uuid]) | ||
|
|
@@ -1409,7 +1425,9 @@ | |
| (if-let [advanced-query (some-> (first (filter #(= ["Custom" "query"] (take 2 %)) (:block.temp/ast-blocks block))) | ||
| (ast->text (select-keys options [:log-fn])) | ||
| string/trim)] | ||
| (let [props {:logseq.property/query (migrate-advanced-query-string advanced-query)} | ||
| (let [props {:logseq.property/query | ||
| (query-refs->id-refs (migrate-advanced-query-string advanced-query) | ||
| page-names-to-uuids)} | ||
| {:keys [block-properties pvalues-tx]} | ||
| (build-properties-and-values props db page-names-to-uuids | ||
| (select-keys block [:block/properties-text-values :block/name :block/title :block/uuid]) | ||
|
|
@@ -1435,7 +1453,7 @@ | |
| :pvalues-tx pvalues-tx'}) | ||
| (if-let [cards-macro (first (:cards walked-ast-blocks))] | ||
| (if-let [query (some-> cards-macro second :arguments first string/trim not-empty)] | ||
| (let [props {:logseq.property/query query} | ||
| (let [props {:logseq.property/query (query-refs->id-refs query page-names-to-uuids)} | ||
| {:keys [block-properties pvalues-tx]} | ||
| (build-properties-and-values props db page-names-to-uuids | ||
| (select-keys block [:block/properties-text-values :block/name :block/title :block/uuid]) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Parenthesized page titles break query parsing
For
(tags [[A]] B) C]]),unmatched-page-ref-close?stops at the title's)before seeing its final]]. The query splits the page title atA, leaving invalid trailing text instead of matchingA]] B) C.Learn more
The scanner decides whether a candidate
]]closes a page reference by searching ahead for another unmatched]]. Stopping that search at every)assumes parentheses cannot occur in page titles, even when a later closing pair is part of the same title. Such page names are valid, and queries using their rendered references no longer parse.Example: A tag titled
A]] B) Cappears as(tags [[A]] B) C]]). The scanner quotes only[[A]]and leavesB) C]])as query syntax rather than matching the tag.Recommended fix: Distinguish a parenthesis inside a reference title from a DSL form closer during lookahead, and restore coverage for
]]followed by)and more title text.Was this helpful? React with 👍 or 👎 to provide feedback.