fix: invalid pages created from cmd-k

Could specify private tags like `P1 #Property` which resulted in invalid
pages. Could also create invalid whiteboards as noticed in
https://discord.com/channels/725182569297215569/725182570131751005/1380146143937433670
This commit is contained in:
Gabriel Horner
2025-06-05 11:53:28 -04:00
parent f6d8595645
commit 4b4c76bef6

View File

@@ -21,7 +21,8 @@
[logseq.common.util :as common-util]
[logseq.common.util.page-ref :as page-ref]
[logseq.db :as ldb]
[promesa.core :as p]))
[promesa.core :as p]
[clojure.set :as set]))
(defn- wrap-tags
"Tags might have multiple words"
@@ -55,8 +56,17 @@
(common-util/split-first (str "#" page-ref/left-brackets) (:block/title parsed-result)))
string/trim)
title)]
(if (and has-tags? (nil? title'))
(notification/show! "Page name can't include \"#\"." :warning)
(cond
(and has-tags? (nil? title'))
(notification/show! "Page name can't include \"#\"." :error)
(and has-tags?
(seq (set/intersection ldb/private-tags (set (map :db/ident (:block/tags parsed-result))))))
(notification/show! (str "New page can't set built-in tags: "
(string/join ", "
(keep #(when (ldb/private-tags (:db/ident %)) (pr-str (:block/title %)))
(:block/tags parsed-result))))
:error)
:else
(when-not (string/blank? title')
(p/let [options' (if db-based?
(cond-> (update options :tags concat (:block/tags parsed-result))