From b359718f4aaf78c97271daecaf11de2181a0ca05 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Tue, 18 Apr 2023 14:01:13 +0800 Subject: [PATCH] fix: insert properties will truncate other properties if there's any empty property (#9117) fix: insert properties not working when there's any empty property --- .../src/logseq/graph_parser/text.cljs | 3 --- src/main/frontend/util/property.cljs | 4 ++-- .../frontend/handler/repo_conversion_test.cljs | 2 +- src/test/frontend/util/property_test.cljs | 16 ++++++++++++++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/deps/graph-parser/src/logseq/graph_parser/text.cljs b/deps/graph-parser/src/logseq/graph_parser/text.cljs index ead6445c5..d24abc873 100644 --- a/deps/graph-parser/src/logseq/graph_parser/text.cljs +++ b/deps/graph-parser/src/logseq/graph_parser/text.cljs @@ -174,9 +174,6 @@ (name k)) v' - (string/blank? v') - nil - (gp-util/wrapped-by-quotes? v') v' diff --git a/src/main/frontend/util/property.cljs b/src/main/frontend/util/property.cljs index 3aa36b293..1aa6081d5 100644 --- a/src/main/frontend/util/property.cljs +++ b/src/main/frontend/util/property.cljs @@ -45,13 +45,13 @@ [line] (boolean (and (string? line) - (re-find (re-pattern (str "^\\s?[^ ]+" gp-property/colons " ")) line)))) + (re-find (re-pattern (str "^\\s?[^ ]+" gp-property/colons)) line)))) (defn front-matter-property? [line] (boolean (and (string? line) - (util/safe-re-find #"^\s*[^ ]+: " line)))) + (util/safe-re-find #"^\s*[^ ]+:" line)))) (defn get-property-key [line format] diff --git a/src/test/frontend/handler/repo_conversion_test.cljs b/src/test/frontend/handler/repo_conversion_test.cljs index 18ddfa083..1ac0db602 100644 --- a/src/test/frontend/handler/repo_conversion_test.cljs +++ b/src/test/frontend/handler/repo_conversion_test.cljs @@ -63,7 +63,7 @@ (is (= {:title 98 :alias 6 - :tags 2 :permalink 2 + :tags 3 :permalink 2 :name 1 :type 1 :related 1 :sample 1 :click 1 :id 1 :example 1} (docs-graph-helper/get-all-page-properties db)) "Counts for all page properties") diff --git a/src/test/frontend/util/property_test.cljs b/src/test/frontend/util/property_test.cljs index 07fea4680..540f093e5 100644 --- a/src/test/frontend/util/property_test.cljs +++ b/src/test/frontend/util/property_test.cljs @@ -49,7 +49,7 @@ "** hello" (property/remove-properties :markdown "** hello\nx:: y\na::b\n") - "** hello\na::b")) + "** hello")) (testing "properties with blank lines" (are [x y] (= x y) @@ -152,7 +152,19 @@ SCHEDULED: <2021-10-25 Mon>\n:PROPERTIES:\n:a: b\n:END:\nworld\n" "c" "d") "a\nfoo:: [[bar]], [[baz]]\nb" (property/insert-properties :markdown "" {:foo "\"bar, baz\""}) - "foo:: \"bar, baz\"")) + "foo:: \"bar, baz\"" + + (property/insert-properties :markdown "abcd\nempty::" {:id "123" :foo "bar"}) + "abcd\nempty::\nid:: 123\nfoo:: bar" + + (property/insert-properties :markdown "abcd\nempty:: " {:id "123" :foo "bar"}) + "abcd\nempty:: \nid:: 123\nfoo:: bar" + + (property/insert-properties :markdown "abcd\nempty::" {:id "123"}) + "abcd\nempty::\nid:: 123" + + (property/insert-properties :markdown "abcd\nempty::\nanother-empty::" {:id "123"}) + "abcd\nempty::\nanother-empty::\nid:: 123")) (deftest test-build-properties-str (are [x y] (= (property/build-properties-str :mardown x) y)