Simplify regexp and ensure it runs against UTF8 chars, closes #1235
This commit is contained in:
parent
4f76e6f577
commit
a8d9695324
|
@ -1,5 +1,9 @@
|
||||||
* bug fix
|
* bug fix
|
||||||
* Properly deprecate setup_mail
|
* Properly deprecate setup_mail
|
||||||
|
* Fix encoding issues with email regexp
|
||||||
|
|
||||||
|
* deprecations
|
||||||
|
* Loosened the used email regexp to simply assert the existent of "@". If someone relies on a more strict regexp, they may use https://github.com/SixArm/sixarm_ruby_email_address_validation
|
||||||
|
|
||||||
== 1.4.2
|
== 1.4.2
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,6 @@ module Devise
|
||||||
autoload :PathChecker, 'devise/path_checker'
|
autoload :PathChecker, 'devise/path_checker'
|
||||||
autoload :Schema, 'devise/schema'
|
autoload :Schema, 'devise/schema'
|
||||||
autoload :TestHelpers, 'devise/test_helpers'
|
autoload :TestHelpers, 'devise/test_helpers'
|
||||||
autoload :Email, 'devise/email'
|
|
||||||
|
|
||||||
module Controllers
|
module Controllers
|
||||||
autoload :Helpers, 'devise/controllers/helpers'
|
autoload :Helpers, 'devise/controllers/helpers'
|
||||||
|
@ -105,11 +104,11 @@ module Devise
|
||||||
mattr_accessor :http_authentication_realm
|
mattr_accessor :http_authentication_realm
|
||||||
@@http_authentication_realm = "Application"
|
@@http_authentication_realm = "Application"
|
||||||
|
|
||||||
# Email regex used to validate email formats. Based on RFC 822 and
|
# Email regex used to validate email formats. It simply asserts that
|
||||||
# retrieved from Sixarm email validation gem
|
# an one (and only one) @ exists in the given string. This is mainly
|
||||||
# (https://github.com/SixArm/sixarm_ruby_email_address_validation).
|
# to give user feedback and not to assert the e-mail validity.
|
||||||
mattr_accessor :email_regexp
|
mattr_accessor :email_regexp
|
||||||
@@email_regexp = Devise::Email::EXACT_PATTERN
|
@@email_regexp = /\A[^@]+@[^@]+\z/
|
||||||
|
|
||||||
# Range validation for password length
|
# Range validation for password length
|
||||||
mattr_accessor :password_length
|
mattr_accessor :password_length
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
# This e-mail validation regexes were retrieved from SixArm Ruby
|
|
||||||
# e-mail validation gem (https://github.com/SixArm/sixarm_ruby_email_address_validation)
|
|
||||||
# As said on https://github.com/SixArm/sixarm_ruby_email_address_validation/blob/master/LICENSE.txt,
|
|
||||||
# we added it using Ruby license terms.
|
|
||||||
|
|
||||||
module Devise
|
|
||||||
module Email
|
|
||||||
QTEXT = Regexp.new '[^\\x0d\\x22\\x5c\\x80-\\xff]', nil, 'n'
|
|
||||||
DTEXT = Regexp.new '[^\\x0d\\x5b-\\x5d\\x80-\\xff]', nil, 'n'
|
|
||||||
ATOM = Regexp.new '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+', nil, 'n'
|
|
||||||
QUOTED_PAIR = Regexp.new '\\x5c[\\x00-\\x7f]', nil, 'n'
|
|
||||||
DOMAIN_LITERAL = Regexp.new "\\x5b(?:#{DTEXT}|#{QUOTED_PAIR})*\\x5d", nil, 'n'
|
|
||||||
QUOTED_STRING = Regexp.new "\\x22(?:#{QTEXT}|#{QUOTED_PAIR})*\\x22", nil, 'n'
|
|
||||||
DOMAIN_REF = ATOM
|
|
||||||
SUB_DOMAIN = "(?:#{DOMAIN_REF}|#{DOMAIN_LITERAL})"
|
|
||||||
WORD = "(?:#{ATOM}|#{QUOTED_STRING})"
|
|
||||||
DOMAIN = "#{SUB_DOMAIN}(?:\\x2e#{SUB_DOMAIN})*"
|
|
||||||
LOCAL_PART = "#{WORD}(?:\\x2e#{WORD})*"
|
|
||||||
SPEC = "#{LOCAL_PART}\\x40#{DOMAIN}"
|
|
||||||
PATTERN = Regexp.new "#{SPEC}", nil, 'n'
|
|
||||||
EXACT_PATTERN = Regexp.new "\\A#{SPEC}\\z", nil, 'n'
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -105,8 +105,10 @@ Devise.setup do |config|
|
||||||
# Range for password length. Default is 6..128.
|
# Range for password length. Default is 6..128.
|
||||||
# config.password_length = 6..128
|
# config.password_length = 6..128
|
||||||
|
|
||||||
# Regex to use to validate the email address
|
# Email regex used to validate email formats. It simply asserts that
|
||||||
# config.email_regexp = /\A([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})\z/i
|
# 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.
|
||||||
|
# config.email_regexp = /\A[^@]+@[^@]+\z/
|
||||||
|
|
||||||
# ==> Configuration for :timeoutable
|
# ==> Configuration for :timeoutable
|
||||||
# The time you want to timeout the user session without activity. After this
|
# The time you want to timeout the user session without activity. After this
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
# encoding: UTF-8
|
||||||
require 'test_helper'
|
require 'test_helper'
|
||||||
|
|
||||||
class ValidatableTest < ActiveSupport::TestCase
|
class ValidatableTest < ActiveSupport::TestCase
|
||||||
|
@ -28,7 +29,7 @@ class ValidatableTest < ActiveSupport::TestCase
|
||||||
assert user.invalid?
|
assert user.invalid?
|
||||||
assert_not_equal 'is invalid', user.errors[:email].join
|
assert_not_equal 'is invalid', user.errors[:email].join
|
||||||
|
|
||||||
%w(invalid_email_format 123 $$$ \(\) ).each do |email|
|
%w{invalid_email_format 123 $$$ () ☃}.each do |email|
|
||||||
user.email = email
|
user.email = email
|
||||||
assert user.invalid?, 'should be invalid with email ' << email
|
assert user.invalid?, 'should be invalid with email ' << email
|
||||||
assert_equal 'is invalid', user.errors[:email].join
|
assert_equal 'is invalid', user.errors[:email].join
|
||||||
|
@ -39,7 +40,7 @@ class ValidatableTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test 'should accept valid emails' do
|
test 'should accept valid emails' do
|
||||||
%w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test).each do |email|
|
%w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test 1☃3@mail.test).each do |email|
|
||||||
user = new_user(:email => email)
|
user = new_user(:email => email)
|
||||||
assert user.valid?, 'should be valid with email ' << email
|
assert user.valid?, 'should be valid with email ' << email
|
||||||
assert_blank user.errors[:email]
|
assert_blank user.errors[:email]
|
||||||
|
|
Loading…
Reference in New Issue