Jelajahi Sumber

Loosen property name check for db graphs

properties don't need to be keywords for db graphs since property names
aren't involved in property storage. This change allows for property
names to have whitespace and be invalid edn.

See #6753 for example bugs that db-validation-property-name? catches
Gabriel Horner 2 tahun lalu
induk
melakukan
6537f0dfab

+ 14 - 8
deps/graph-parser/src/logseq/graph_parser/property.cljs

@@ -21,14 +21,6 @@
        (map #(str (name (key %)) (str colons " ") (val %)))
        (map #(str (name (key %)) (str colons " ") (val %)))
        (string/join "\n")))
        (string/join "\n")))
 
 
-(defn valid-property-name?
-  [s]
-  {:pre [(string? s)]}
-  (and (gp-util/valid-edn-keyword? s)
-       (not (re-find #"[\"|^|(|)|{|}]+" s))
-       ;; Disallow tags as property names
-       (not (re-find #"^:#" s))))
-
 (defn properties-ast?
 (defn properties-ast?
   [block]
   [block]
   (and
   (and
@@ -39,6 +31,14 @@
 ;; Configuration and fns for older, file graph properties
 ;; Configuration and fns for older, file graph properties
 ;; =============
 ;; =============
 
 
+(defn valid-property-name?
+  [s]
+  {:pre [(string? s)]}
+  (and (gp-util/valid-edn-keyword? s)
+       (not (re-find #"[\"|^|(|)|{|}]+" s))
+       ;; Disallow tags as property names
+       (not (re-find #"^:#" s))))
+
 ;; Built-in properties are properties that logseq uses for its features. Most of
 ;; Built-in properties are properties that logseq uses for its features. Most of
 ;; these properties are hidden from the user but a few like the editable ones
 ;; these properties are hidden from the user but a few like the editable ones
 ;; are visible for the user to edit.
 ;; are visible for the user to edit.
@@ -207,3 +207,9 @@
 
 
 (defonce db-built-in-properties-keys-str
 (defonce db-built-in-properties-keys-str
   (set (map name (keys db-built-in-properties))))
   (set (map name (keys db-built-in-properties))))
+
+(defn db-valid-property-name?
+  [s]
+  {:pre [(string? s)]}
+  ;; Disallow tags or page refs as they would create unreferenceable page names
+  (not (re-find #"^(#|\[\[)" s)))

+ 2 - 2
src/main/frontend/components/property.cljs

@@ -338,7 +338,7 @@
           (let [editor-id (str "ls-property-" blocks-container-id (:db/id entity) "-" (:db/id property))]
           (let [editor-id (str "ls-property-" blocks-container-id (:db/id entity) "-" (:db/id property))]
             (set-editing! property editor-id "" ""))))
             (set-editing! property editor-id "" ""))))
       ;; new property
       ;; new property
-      (if (gp-property/valid-property-name? (str ":" property-name))
+      (if (gp-property/db-valid-property-name? property-name)
         (if (= "class" (:block/type entity))
         (if (= "class" (:block/type entity))
           (add-property! entity property-name "" {:class-schema? class-schema?})
           (add-property! entity property-name "" {:class-schema? class-schema?})
           (do
           (do
@@ -346,7 +346,7 @@
             ;; configure new property
             ;; configure new property
             (when-let [property (get-property-from-db property-name)]
             (when-let [property (get-property-from-db property-name)]
               (state/set-sub-modal! #(property-config repo property)))))
               (state/set-sub-modal! #(property-config repo property)))))
-        (do (notification/show! "This is an invalid property name. A property name cannot start with non-alphanumeric characters e.g. '#' or '[['." :error)
+        (do (notification/show! "This is an invalid property name. A property name cannot start with page reference characters '#' or '[['." :error)
             (exit-edit-property))))))
             (exit-edit-property))))))
 
 
 (rum/defcs property-input < rum/reactive
 (rum/defcs property-input < rum/reactive