Browse Source

fix(fs): add unicode normalize to path-fn

This is a catch-all type fix
Andelf 2 years ago
parent
commit
51201124ff

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

@@ -6,7 +6,7 @@
 (defn- safe-decode-uri-component
   [uri]
   (try
-    (js/decodeURIComponent uri)
+    (.normalize (js/decodeURIComponent uri) "NFC")
     (catch :default _
       (js/console.error "decode-uri-component-failed" uri)
       uri)))
@@ -157,7 +157,6 @@
 (defn path-join
   "Join path segments, or URL base and path segments"
   [base & segments]
-
   (cond
     ;; For debugging
     ; (nil? base)
@@ -190,9 +189,10 @@
 (defn path-normalize
   "Normalize path or URL"
   [path]
-  (if (is-file-url? path)
-    (url-normalize path)
-    (path-normalize-internal path)))
+  (-> (if (is-file-url? path)
+        (url-normalize path)
+        (path-normalize-internal path))
+      (.normalize "NFC")))
 
 (defn url-to-path
   "Extract path part of a URL, decoded.

+ 1 - 2
src/main/frontend/fs/capacitor_fs.cljs

@@ -238,8 +238,7 @@
              (when-not contents-matched?
                (backup-file repo-dir :backup-dir fpath disk-content))
              (db/set-file-last-modified-at! repo rpath mtime)
-             (p/let [content content]
-               (db/set-file-content! repo rpath content))
+             (db/set-file-content! repo rpath content)
              (when ok-handler
                (ok-handler repo fpath result))
              result)

+ 3 - 3
src/main/frontend/handler/common/file.cljs

@@ -74,13 +74,13 @@
      :fs/reset-event - the event that triggered the file update
        :fs/local-file-change - file changed on local disk
        :fs/remote-file-change - file changed on remote"
-  [repo-url file content {:fs/keys [event] :as options}]
+  [repo-url file-path content {:fs/keys [event] :as options}]
   (let [db-conn (db/get-db repo-url false)]
     (case event
       ;; the file is already in db, so we can use the existing file's blocks
       ;; to do the diff-merge
       :fs/local-file-change
-      (graph-parser/parse-file db-conn file content (assoc-in options [:extract-options :resolve-uuid-fn] diff-merge-uuids-2ways))
+      (graph-parser/parse-file db-conn file-path content (assoc-in options [:extract-options :resolve-uuid-fn] diff-merge-uuids-2ways))
 
       ;; TODO Junyi: 3 ways to handle remote file change
       ;; The file is on remote, so we should have 
@@ -90,7 +90,7 @@
       ;;   2. a "remote version" just fetched from remote
 
       ;; default to parse the file
-      (graph-parser/parse-file db-conn file content options))))
+      (graph-parser/parse-file db-conn file-path content options))))
 
 (defn reset-file!
   "Main fn for updating a db with the results of a parsed file"