fix(sync): unify path-normalize and filter out un-normalized files

This commit is contained in:
rcmerci
2022-11-21 18:37:19 +08:00
committed by Tienson Qin
parent 6c8f6741f7
commit 81f90cd34d
2 changed files with 55 additions and 29 deletions

View File

@@ -235,8 +235,7 @@
path))
path))
(defn normalize-file-protocol-path [dir path & {:keys [normalize?]
:or {normalize? true}}]
(defn normalize-file-protocol-path [dir path]
(let [dir (some-> dir (string/replace #"/+$" ""))
dir (if (and (not-empty dir) (string/starts-with? dir "/"))
(do
@@ -244,15 +243,16 @@
(str "file://" (js/encodeURI dir)))
dir)
path (some-> path (string/replace #"^/+" ""))
normalize-f (if normalize? gp-util/path-normalize identity)
normalize-f gp-util/path-normalize
encodeURI-f js/encodeURI
safe-encode-url #(let [encoded-chars?
(and (string? %) (boolean (re-find #"(?i)%[0-9a-f]{2}" %)))]
(cond
(not encoded-chars?)
(js/encodeURI %)
(encodeURI-f (normalize-f %))
:else
(js/encodeURI (normalize-f (js/decodeURI %)))))
(encodeURI-f (normalize-f (js/decodeURI %)))))
path' (cond
(and path (string/starts-with? path "file:/"))
(safe-encode-url path)