1
0
Fork 0
mirror of https://github.com/heartcombo/devise.git synced 2022-11-09 12:18:31 -05:00

Merge pull request #2148 from kukula/master

Fix default email_regexp config to not allow spaces
This commit is contained in:
José Valim 2012-11-21 02:58:30 -08:00
commit 3696cbf33e
2 changed files with 13 additions and 2 deletions

View file

@ -87,7 +87,7 @@ module Devise
# an one (and only one) @ exists in the given string. This is mainly # an one (and only one) @ exists in the given string. This is mainly
# to give user feedback and not to assert the e-mail validity. # to give user feedback and not to assert the e-mail validity.
mattr_accessor :email_regexp mattr_accessor :email_regexp
@@email_regexp = /\A[^@]+@([^@\.]+\.)+[^@\.]+\z/ @@email_regexp = /\A[^@\s]+@([^@\s]+\.)+[^@\s]+\z/
# Range validation for password length # Range validation for password length
mattr_accessor :password_length mattr_accessor :password_length

View file

@ -69,4 +69,15 @@ class DeviseTest < ActiveSupport::TestCase
assert_not Devise.secure_compare("size_1", "size_four") assert_not Devise.secure_compare("size_1", "size_four")
end end
test 'Devise.email_regexp should match valid email addresses' do
valid_emails = ["test@example.com", "jo@jo.co", "f4$_m@you.com", "testing.example@example.com.ua"]
non_valid_emails = ["rex", "test@go,com", "test user@example.com", "test_user@example server.com"]
valid_emails.each do |email|
assert_match Devise.email_regexp, email
end
non_valid_emails.each do |email|
assert_no_match Devise.email_regexp, email
end
end
end end