mirror of https://github.com/logseq/logseq
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? catchespull/10016/head
parent
8253477a9d
commit
6537f0dfab
|
@ -21,14 +21,6 @@
|
|||
(map #(str (name (key %)) (str colons " ") (val %)))
|
||||
(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?
|
||||
[block]
|
||||
(and
|
||||
|
@ -39,6 +31,14 @@
|
|||
;; 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
|
||||
;; these properties are hidden from the user but a few like the editable ones
|
||||
;; are visible for the user to edit.
|
||||
|
@ -207,3 +207,9 @@
|
|||
|
||||
(defonce db-built-in-properties-keys-str
|
||||
(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)))
|
|
@ -338,7 +338,7 @@
|
|||
(let [editor-id (str "ls-property-" blocks-container-id (:db/id entity) "-" (:db/id property))]
|
||||
(set-editing! property editor-id "" ""))))
|
||||
;; 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))
|
||||
(add-property! entity property-name "" {:class-schema? class-schema?})
|
||||
(do
|
||||
|
@ -346,7 +346,7 @@
|
|||
;; configure new property
|
||||
(when-let [property (get-property-from-db property-name)]
|
||||
(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))))))
|
||||
|
||||
(rum/defcs property-input < rum/reactive
|
||||
|
|
Loading…
Reference in New Issue