浏览代码

test(fs): simple test for protocol-url

Andelf 2 年之前
父节点
当前提交
880ea8b00e
共有 2 个文件被更改,包括 13 次插入1 次删除
  1. 1 1
      deps/common/src/logseq/common/path.cljs
  2. 12 0
      deps/common/test/logseq/common/path_test.cljs

+ 1 - 1
deps/common/src/logseq/common/path.cljs

@@ -315,5 +315,5 @@
 
    This is a loose check, it only checks if there is a valid protocol prefix."
   [p]
-  (boolean (and (re-find #"^[a-zA-Z0-9_+\-\.]+:" p)
+  (boolean (and (re-find #"^[a-zA-Z0-9_+\-\.]{2,}:" p) ;; HACK: avoid matching windows drive
                 (not (string/includes? p " ")))))

+ 12 - 0
deps/common/test/logseq/common/path_test.cljs

@@ -45,3 +45,15 @@
     (is (false? (path/absolute? "test.md")))
     (is (false? (path/absolute? "test")))
     (is (false? (path/absolute? "D:test.md")))))
+
+(deftest protocol-url
+  (testing "protocol url"
+    (is (true? (path/protocol-url? "mailto:[email protected]")))
+    (is (true? (path/protocol-url? "https://logseq.com")))
+    (is (true? (path/protocol-url? "ftp://logseq.com")))
+    (is (true? (path/protocol-url? "file:///home/xxx/logseq/test.md")))
+    (is (true? (path/protocol-url? "assets:///home/xxx/logseq/test.md")))
+    (is (false? (path/protocol-url? "logseq/test.md")))
+    (is (false? (path/protocol-url? "test.md")))
+    (is (false? (path/protocol-url? "test")))
+    (is (false? (path/protocol-url? "D:test.md")))))