Skip to content

Commit c83036f

Browse files
cursoragenttiensonqin
authored andcommitted
fix: stop page-ref lookahead at a sibling page ref
After a form close, [[ starts the next argument, so a later title ending in ]] cannot swallow an earlier between date. Co-authored-by: Tienson Qin <tiensonqin@gmail.com>
1 parent caf574b commit c83036f

3 files changed

Lines changed: 23 additions & 5 deletions

File tree

‎deps/db/src/logseq/db/frontend/query_dsl.cljs‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,18 @@
4040
i))))
4141

4242
(defn- next-form-start?
43-
"True when text after a `)` is a sibling DSL list or the end of input,
44-
not more page-title text."
43+
"True when text after a `)` is a sibling DSL form or the end of input,
44+
not more page-title text. A following `[[` is a page-ref argument, not
45+
more of the current title."
4546
[s i]
4647
(let [i (skip-ws s i)
4748
n (count s)]
4849
(or (>= i n)
49-
(= \( (nth s i)))))
50+
(= \( (nth s i))
51+
(= \# (nth s i))
52+
(and (= \[ (nth s i))
53+
(< (inc i) n)
54+
(= \[ (nth s (inc i)))))))
5055

5156
(defn- unmatched-page-ref-close?
5257
"True when `s` from `start` still contains a `]]` that is not paired with a

‎deps/db/test/logseq/db/frontend/query_dsl_test.cljs‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,4 +111,12 @@
111111
(is (= (quoted-tags-query "A]] B) C")
112112
(query-dsl/pre-transform "(tags [[A]] B) C]])")))
113113
(is (= '(tags "[[A]] B) C]]")
114-
(read-query "(tags [[A]] B) C]])")))))
114+
(read-query "(tags [[A]] B) C]])"))))
115+
116+
(testing "later page-ref sibling ending with ]] does not swallow a between date"
117+
(is (= (str "(and (between " (pr-str "[[Dec 26th, 2020]]") " tomorrow) "
118+
(pr-str "[[foo]]]]") ")")
119+
(query-dsl/pre-transform
120+
"(and (between [[Dec 26th, 2020]] tomorrow) [[foo]]]])")))
121+
(is (= (list 'and (list 'between "[[Dec 26th, 2020]]" 'tomorrow) "[[foo]]]]")
122+
(read-query "(and (between [[Dec 26th, 2020]] tomorrow) [[foo]]]])")))))

‎src/test/frontend/db/query_dsl_test.cljs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,12 @@
188188
(str "(and (between [[Dec 26th, 2020]] tomorrow) (tags "
189189
(str "[[" "bar" "]]" "]]") "))"))))
190190
(is (= (quote-tags (str "A" "]]" " B) C"))
191-
(query-dsl/pre-transform (wrap-tags (str "A" "]]" " B) C"))))))))
191+
(query-dsl/pre-transform (wrap-tags (str "A" "]]" " B) C")))))
192+
(is (= (str "(and (between " (pr-str "[[Dec 26th, 2020]]") " tomorrow) "
193+
(pr-str (str "[[" "foo" "]]" "]]")) ")")
194+
(query-dsl/pre-transform
195+
(str "(and (between [[Dec 26th, 2020]] tomorrow) "
196+
(str "[[" "foo" "]]" "]]") ")")))))))
192197

193198
(defn- testable-content
194199
"Only test :block/title up to page-ref to make tests readable"

0 commit comments

Comments
 (0)