[Fix #3604] ui, screens, browser, events: deduplicate browser history hence chat elements

This commit is contained in:
Kenneth Tilton 2018-07-23 05:47:59 -04:00 committed by Roman Volosovskyi
parent 0530f9c8dd
commit 48cc45ec6f
No known key found for this signature in database
GPG Key ID: 0238A4B5ECEE70DE
3 changed files with 31 additions and 4 deletions

View File

@ -73,10 +73,13 @@
:open-url-in-browser
[re-frame/trim-v]
(fn [cofx [url]]
(let [browser {:browser-id (random/id)
(let [normalized-url (http/normalize-and-decode-url url)
browser {:browser-id (or (http/url-host normalized-url)
;; purely as a fallback should url not parse...
(random/id))
:name (i18n/label :t/browser)
:history-index 0
:history [(http/normalize-and-decode-url url)]}]
:history [normalized-url]}]
(model/update-browser-and-navigate cofx browser))))
(handlers/register-handler-fx

View File

@ -1,7 +1,9 @@
(ns status-im.utils.http
(:require [status-im.utils.utils :as utils]
[status-im.react-native.js-dependencies :as rn-dependencies]
[taoensso.timbre :as log])
[taoensso.timbre :as log]
[goog.Uri :as uri]
[clojure.string :as string])
(:refer-clojure :exclude [get]))
;; Default HTTP request timeout ms
@ -65,6 +67,13 @@
(def normalize-and-decode-url (comp js/decodeURI normalize-url))
(defn url-host [url]
(try
(when-let [host (.getDomain (goog.Uri. url))]
(when-not (string/blank? host)
host))
(catch :default _ nil)))
(defn parse-payload [o]
(when o
(try

View File

@ -37,4 +37,19 @@
(testing "https://www.etheremon.com/assets/images/mons'><script>\\\\x3Bjavascript:alert(1)</script>origin/025.png"
(testing "it returns false"
(is (not (http/url-sanitized? "https://www.etheremon.com/assets/images/mons'><script>\\\\x3Bjavascript:alert(1)</script>origin/025.png"))))))
(is (not (http/url-sanitized? "https://www.etheremon.com/assets/images/mons'><script>\\\\x3Bjavascript:alert(1)</script>origin/025.png"))))))
(deftest url-host-check
(testing "Extract host/domain from URL"
(testing "Valid URL with endpoint"
(is (= "status.im" (http/url-host "https://status.im/testing"))))
(testing "Valid URL"
(is (= "status.im" (http/url-host "http://status.im"))))
(testing "Blank domainlocalhost"
(is (nil? (http/url-host "localhost:3000/testing")))))
(testing "Return nil for Invalid URL"
(testing "Bad scheme"
(is (nil? (http/url-host "invalid//status.im/testing"))))
(testing "No scheme"
(is (nil? (http/url-host "status.im/testing"))))))