Skip to content

Commit

Permalink
Loosened validation/is-email? to allow for rfc2822 corner cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
pmn committed Aug 2, 2011
1 parent 89c4b3a commit c586b6c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/noir/validation.clj
Expand Up @@ -37,7 +37,7 @@
(defn is-email?
"Returns true if v is an email address"
[v]
(re-matches #"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b" v))
(re-matches #"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?" v))

(declare *errors*)

Expand Down
25 changes: 24 additions & 1 deletion test/noir/test/core.clj
Expand Up @@ -8,7 +8,8 @@
[noir.session :as session]
[noir.options :as options]
[noir.response :as resp]
[noir.cookies :as cookies]))
[noir.cookies :as cookies]
[noir.validation :as vali]))

(deftest hashing
(let [pass (crypt/encrypt "password")]
Expand Down Expand Up @@ -67,3 +68,25 @@
(has-content-type "text/html; charset=utf-8")
(has-body "ąčęė")))

(deftest valid-emails
(are [email] (vali/is-email? email)
"testword@domain.com"
"test+word@domain.com"
"test_word@domain.com"
"test'word@domain.com"
"test`word@domain.com"
"test#word@domain.com"
"test=word@domain.com"
"test|word@domain.com"
"testword@test.domain.com"
"te$t@test.com"
"t`e's.t&w%o#r{d@t.e.s.t"
"x@x.xx"))

(deftest invalid-emails
(are [email] (not (vali/is-email? email))
".test@domain.com"
"-@-.com"
"test"
"test.@domain.com"
"test@com"))

0 comments on commit c586b6c

Please sign in to comment.