From 239ec1252940cf90efd447986f8b5129f57b3643 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Tue, 13 Apr 2021 12:12:56 +0200 Subject: [PATCH] :bug: Fix usability issue on team invitation dialog. Happens when user select (autocompletion), writes or pastes an email that starts and/or ends with a trailing spaces. The new spec allows tailing spaces but conforms to a valid email address without trailing spaces. --- common/app/common/spec.cljc | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/common/app/common/spec.cljc b/common/app/common/spec.cljc index 907395b40..81fc5195d 100644 --- a/common/app/common/spec.cljc +++ b/common/app/common/spec.cljc @@ -25,9 +25,6 @@ ;; --- Constants -(def email-rx - #"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$") - (def uuid-rx #"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$") @@ -86,12 +83,6 @@ v ::s/invalid)) -(defn- email-conformer - [v] - (if (and (string? v) (re-matches email-rx v)) - v - ::s/invalid)) - (defn keyword-conformer [v] (cond @@ -109,7 +100,6 @@ (s/def ::keyword (s/conformer keyword-conformer name)) (s/def ::inst inst?) (s/def ::string string?) -(s/def ::email (s/conformer email-conformer str)) (s/def ::color (s/conformer color-conformer str)) (s/def ::uuid (s/conformer uuid-conformer str)) (s/def ::boolean (s/conformer boolean-conformer boolean-unformer)) @@ -134,6 +124,18 @@ (>= % min-safe-int) (<= % max-safe-int))) + +;; --- SPEC: email + +(let [re #"[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+" + cfn (fn [v] + (if (string? v) + (if-let [matches (re-seq re v)] + (first matches) + (do ::s/invalid)) + ::s/invalid))] + (s/def ::email (s/conformer cfn str))) + ;; --- Macros (defn spec-assert*