From c3449a3a65764e1de2cfa4c10fe1c674b59d2a98 Mon Sep 17 00:00:00 2001 From: Foo Pang Date: Thu, 15 Mar 2018 17:47:32 +0800 Subject: [PATCH] [Fix #3572] regx parse string bug in formatted texts Signed-off-by: Julien Eluard --- src/status_im/chat/views/message/message.cljs | 2 +- test/cljs/status_im/test/chat/views/message.cljs | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/status_im/chat/views/message/message.cljs b/src/status_im/chat/views/message/message.cljs index 99df1f044f..d9ccbcf496 100644 --- a/src/status_im/chat/views/message/message.cljs +++ b/src/status_im/chat/views/message/message.cljs @@ -103,7 +103,7 @@ (defn- parse-str-regx [string regx matched-fn unmatched-fn] (if (string? string) (let [unmatched-text (as-> (->> (string/split string regx) - (remove empty?) + (remove nil?) vec) $ (if (zero? (count $)) [nil] diff --git a/test/cljs/status_im/test/chat/views/message.cljs b/test/cljs/status_im/test/chat/views/message.cljs index 828ccb4cd2..965c4eeaae 100644 --- a/test/cljs/status_im/test/chat/views/message.cljs +++ b/test/cljs/status_im/test/chat/views/message.cljs @@ -3,13 +3,16 @@ [status-im.chat.views.message.message :as message])) (deftest parse-url - (is (= (lazy-seq [nil {:text "www.google.com" :url? true}]) + (is (= (lazy-seq [{:text "" :url? false} + {:text "www.google.com" :url? true}]) (message/parse-url "www.google.com"))) - (is (= (lazy-seq [nil {:text "status.im" :url? true}]) + (is (= (lazy-seq [{:text "" :url? false} + {:text "status.im" :url? true}]) (message/parse-url "status.im"))) (is (= (lazy-seq [{:text "$33.90" :url? false} nil]) (message/parse-url "$33.90"))) - (is (= (lazy-seq [nil {:text "https://www.google.com/?gfe_rd=cr&dcr=0&ei=P9-CWuyBGaro8AeqkYGQDQ&gws_rd=cr&fg=1" :url? true}]) + (is (= (lazy-seq [{:text "" :url? false} + {:text "https://www.google.com/?gfe_rd=cr&dcr=0&ei=P9-CWuyBGaro8AeqkYGQDQ&gws_rd=cr&fg=1" :url? true}]) (message/parse-url "https://www.google.com/?gfe_rd=cr&dcr=0&ei=P9-CWuyBGaro8AeqkYGQDQ&gws_rd=cr&fg=1"))) (is (= (lazy-seq [{:text "Status - " :url? false} {:text "https://github.com/status-im/status-react" :url? true}