Skip to content

Commit

Permalink
Disallow tags as property names - fix logseq#6753
Browse files Browse the repository at this point in the history
  • Loading branch information
logseq-cldwalker authored and tiensonqin committed Oct 19, 2022
1 parent 87cc0af commit daf6541
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
6 changes: 4 additions & 2 deletions deps/graph-parser/src/logseq/graph_parser/property.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@

(defn valid-property-name?
[s]
[:pre (string? s)]
{:pre [(string? s)]}
(and (gp-util/valid-edn-keyword? s)
(not (re-find #"[\"|^|(|)|{|}]+" s))))
(not (re-find #"[\"|^|(|)|{|}]+" s))
;; Disallow tags as property names
(not (re-find #"^:#" s))))

(defn properties-ast?
[block]
Expand Down
7 changes: 4 additions & 3 deletions deps/graph-parser/test/logseq/graph_parser_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,14 @@
(let [conn (ldb/start-conn)
properties {"foo" "valid"
"[[foo]]" "invalid"
"some,prop" "invalid"}
"some,prop" "invalid"
"#blarg" "invalid"}
body (str (gp-property/->block-content properties)
"\n- " (gp-property/->block-content properties))]
(graph-parser/parse-file conn "foo.md" body {})

(is (= [{:block/properties {:foo "valid"}
:block/invalid-properties #{"[[foo]]" "some,prop"}}]
:block/invalid-properties #{"[[foo]]" "some,prop" "#blarg"}}]
(->> (d/q '[:find (pull ?b [*])
:in $
:where
Expand All @@ -303,7 +304,7 @@
"Has correct (in)valid block properties")

(is (= [{:block/properties {:foo "valid"}
:block/invalid-properties #{"[[foo]]" "some,prop"}}]
:block/invalid-properties #{"[[foo]]" "some,prop" "#blarg"}}]
(->> (d/q '[:find (pull ?b [*])
:in $
:where [?b :block/properties] [?b :block/name]]
Expand Down

0 comments on commit daf6541

Please sign in to comment.