Просмотр исходного кода

Fix url? detection for raw paste case - fix #7297

Gabriel Horner 2 лет назад
Родитель
Сommit
1c3ef2ccb5

+ 1 - 2
deps/graph-parser/src/logseq/graph_parser/util.cljs

@@ -83,8 +83,7 @@
   [s]
   (and (string? s)
        (try
-         (js/URL. s)
-         true
+         (not (contains? #{nil "null"} (.-origin (js/URL. s))))
          (catch :default _e
            false))))
 

+ 7 - 0
deps/graph-parser/test/logseq/graph_parser/util_test.cljs

@@ -28,3 +28,10 @@
        "/root/Documents/audio" nil
        "/root/Documents/audio." nil
        "special/characters/aäääöüß.7z" "7z"))
+
+(deftest url?
+  (are [x y]
+       (= (gp-util/url? x) y)
+       "http://logseq.com" true
+       "prop:: value" false
+       "a:" false))

+ 18 - 0
src/test/frontend/handler/paste_test.cljs

@@ -8,6 +8,7 @@
             [frontend.util :as util]
             [promesa.core :as p]
             [frontend.extensions.html-parser :as html-parser]
+            [frontend.handler.editor :as editor-handler]
             [frontend.handler.paste :as paste-handler]))
 
 (deftest try-parse-as-json-result-parse-test
@@ -110,3 +111,20 @@
                         #js {:clipboardData #js {:getData (constantly clipboard)}})]
                (is (= expected-paste result))
                (reset))))))
+
+(deftest-async editor-on-paste-raw-with-selection
+  (let [clipboard "after"
+        expected-paste "after"
+        selected-text "before"
+        block-content "test:: before"]
+    (test-helper/with-reset
+      reset
+      [utils/getClipText (fn [cb] (cb clipboard))
+       state/get-input (constantly #js {:value block-content})
+       editor-handler/get-selection-and-format (constantly {:value block-content})
+       commands/delete-selection! (constantly nil)
+       commands/simple-insert! (fn [_input text] (p/resolved text))
+       util/get-selected-text (constantly selected-text)]
+      (p/let [result ((paste-handler/editor-on-paste! nil true))]
+             (is (= expected-paste result))
+             (reset)))))