From 0a9919c991201ae764d15ad074975cb3f1c06578 Mon Sep 17 00:00:00 2001 From: "Michael Bradley, Jr" Date: Wed, 15 Apr 2020 11:31:28 -0500 Subject: [PATCH] fix: strip leading and trailing whitespace from QR Code data All leading and trailing whitespace is now removed from strings derived from QR codes, both in the case of `get-qr-code-data` (real camera) and `qr-test-view` (mock camera). Signed-off-by: Andrey Shovkoplyas --- src/status_im/ui/components/camera.cljs | 4 +++- src/status_im/ui/screens/qr_scanner/views.cljs | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/status_im/ui/components/camera.cljs b/src/status_im/ui/components/camera.cljs index 7eb7c5ac5c..c95c93616e 100644 --- a/src/status_im/ui/components/camera.cljs +++ b/src/status_im/ui/components/camera.cljs @@ -1,6 +1,7 @@ (ns status-im.ui.components.camera (:require [goog.object :as object] [reagent.core :as reagent] + [clojure.string :as string] [clojure.walk :as walk] [status-im.react-native.js-dependencies :as js-dependencies] [status-im.utils.platform :as platform])) @@ -34,4 +35,5 @@ (reagent/create-element default-camera (clj->js (merge {:inverted true} props)))) (defn get-qr-code-data [code] - (.-data code)) + (when-let [data (.-data code)] + (string/trim data))) diff --git a/src/status_im/ui/screens/qr_scanner/views.cljs b/src/status_im/ui/screens/qr_scanner/views.cljs index 1783ef8837..57da776de2 100644 --- a/src/status_im/ui/screens/qr_scanner/views.cljs +++ b/src/status_im/ui/screens/qr_scanner/views.cljs @@ -1,6 +1,7 @@ (ns status-im.ui.screens.qr-scanner.views (:require-macros [status-im.utils.views :refer [defview letsubs]]) (:require [re-frame.core :as re-frame] + [clojure.string :as string] [status-im.i18n :as i18n] [status-im.ui.components.camera :as camera] [status-im.ui.components.react :as react] @@ -42,7 +43,7 @@ :on-press #(re-frame/dispatch [:qr-scanner.callback/scan-qr-code-cancel opts])}] [button/button {:label "OK" - :on-press #(re-frame/dispatch [:qr-scanner.callback/scan-qr-code-success opts @text-value])}]]]])) + :on-press #(re-frame/dispatch [:qr-scanner.callback/scan-qr-code-success opts (when-let [text @text-value] (string/trim text))])}]]]])) (defn corner [border1 border2 corner] [react/view (assoc {:border-color colors/white-persist :width 60 :height 60} border1 5 border2 5 corner 32)])