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

pull/8774/head^2
Gabriel Horner 2023-03-16 14:43:11 -04:00 committed by Gabriel Horner
parent 2c987d0c6a
commit 1c3ef2ccb5
3 changed files with 26 additions and 2 deletions

View File

@ -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))))

View File

@ -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))

View File

@ -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)))))