Просмотр исходного кода

fix: property name allows page ref characters when editing

that are disallowed at creation time. We should be consistent with
our validation of property names
Gabriel Horner 7 месяцев назад
Родитель
Сommit
5142030912

+ 2 - 1
deps/outliner/src/logseq/outliner/property.cljs

@@ -109,7 +109,8 @@
   (when (and (some? property-name) (not= property-name (:block/title property)))
     (outliner-validate/validate-page-title property-name {:node property})
     (outliner-validate/validate-page-title-characters property-name {:node property})
-    (outliner-validate/validate-block-title @conn property-name property))
+    (outliner-validate/validate-block-title @conn property-name property)
+    (outliner-validate/validate-property-title property-name))
 
   (let [changed-property-attrs
         ;; Only update property if something has changed as we are updating a timestamp

+ 12 - 2
deps/outliner/src/logseq/outliner/validate.cljs

@@ -8,7 +8,8 @@
             [logseq.common.util.namespace :as ns-util]
             [logseq.db :as ldb]
             [logseq.db.frontend.class :as db-class]
-            [logseq.db.frontend.entity-util :as entity-util]))
+            [logseq.db.frontend.entity-util :as entity-util]
+            [logseq.db.frontend.property :as db-property]))
 
 (defn ^:api validate-page-title-characters
   "Validates characters that must not be in a page title"
@@ -138,12 +139,21 @@
                                :type :warning}}))))
 
 (defn validate-block-title
-  "Validates a block title when it has changed"
+  "Validates a block title when it has changed for a ldb/page? or tagged node"
   [db new-title existing-block-entity]
   (validate-built-in-pages existing-block-entity)
   (validate-unique-by-name-tag-and-block-type db new-title existing-block-entity)
   (validate-disallow-page-with-journal-name new-title existing-block-entity))
 
+(defn validate-property-title
+  "Validates a property's title when it has changed"
+  [new-title]
+  (when-not (db-property/valid-property-name? new-title)
+    (throw (ex-info "Property name is invalid"
+                    {:type :notification
+                     :payload {:message "This is an invalid property name. A property name cannot start with page reference characters '#' or '[['."
+                               :type :error}}))))
+
 (defn- validate-parent-property-have-same-type
   "Validates whether given parent and children are valid. Allows 'class' and
   'page' types to have a relationship with their own type. May consider allowing more