Skip to content

Commit

Permalink
Fix mailto and other links creating invalid pages
Browse files Browse the repository at this point in the history
Fixes logseq#9346 and fixes logseq#5926.
Also fixes case where relative paths for unsupported paths were creating
pages per directory e.g. `deps/graph-parser/yarn.lock` created deps and
graph-parser pages
  • Loading branch information
logseq-cldwalker authored and tiensonqin committed May 11, 2023
1 parent adef15d commit b26d83d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 18 deletions.
13 changes: 0 additions & 13 deletions deps/graph-parser/src/logseq/graph_parser/block.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -54,19 +54,6 @@
(page-ref/page-ref? value)
(text/page-ref-un-brackets! value))

(and
(= typ "Search")
(not (contains? #{\# \* \/ \[} (first value)))
;; FIXME: use `gp-util/get-format` instead
(let [ext (some-> (gp-util/get-file-ext value) keyword)]
(when (and (not (string/starts-with? value "http:"))
(not (string/starts-with? value "https:"))
(not (string/starts-with? value "file:"))
(not (gp-config/local-asset? value))
(or (#{:excalidraw :tldr} ext)
(not (contains? supported-formats ext))))
value)))

(and
(= typ "File")
(second (first (:label (second block)))))))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
;; only increase over time as the docs graph rarely has deletions
(testing "Counts"
(is (= 306 (count files)) "Correct file count")
(is (= 69508 (count (d/datoms db :eavt))) "Correct datoms count")
(is (= 69500 (count (d/datoms db :eavt))) "Correct datoms count")

(is (= 5866
(ffirst
Expand Down
12 changes: 9 additions & 3 deletions deps/graph-parser/test/logseq/graph_parser_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -360,15 +360,21 @@
(remove built-in-pages)
set)))))

(testing "for file and web uris"
(testing "for file, mailto, web and other uris"
(let [conn (ldb/start-conn)
built-in-pages (set (map string/lower-case default-db/built-in-pages-names))]
(graph-parser/parse-file conn
"foo.md"
(str "- [Filename.txt](file:///E:/test/Filename.txt)\n"
(str "- [foo]([[bar]])\n"
;; all of the uris below do not create pages
"- ![image.png](../assets/image_1630480711363_0.png)\n"
"- [Filename.txt](file:///E:/test/Filename.txt)\n"
"- [mail](mailto:[email protected]?subject=TestSubject)\n"
"- [onenote link](onenote:https://d.docs.live.net/b2127346582e6386a/blablabla/blablabla/blablabla%20blablabla.one#Etat%202019&section-id={133DDF16-9A1F-4815-9A05-44303784442E6F94}&page-id={3AAB677F0B-328F-41D0-AFF5-66408819C085}&end)\n"
"- [lock file](deps/graph-parser/yarn.lock)"
"- [example](https://example.com)")
{})
(is (= #{"foo"}
(is (= #{"foo" "bar"}
(->> (d/q '[:find (pull ?b [*])
:in $
:where [?b :block/name]]
Expand Down
2 changes: 1 addition & 1 deletion src/test/frontend/handler/repo_conversion_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
;; only increase over time as the docs graph rarely has deletions
(testing "Counts"
(is (= 211 (count files)) "Correct file count")
(is (= 42312 (count (d/datoms db :eavt))) "Correct datoms count")
(is (= 42296 (count (d/datoms db :eavt))) "Correct datoms count")

(is (= 3600
(ffirst
Expand Down

0 comments on commit b26d83d

Please sign in to comment.