Commit 1d773577 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'email_with_apostrophe' into 'master'

Email with apostrophe

Fixes #1225
parents ed610043 f43e4197
...@@ -50,9 +50,6 @@ gem "grape", "~> 0.6.1" ...@@ -50,9 +50,6 @@ gem "grape", "~> 0.6.1"
gem "grape-entity", "~> 0.4.2" gem "grape-entity", "~> 0.4.2"
gem 'rack-cors', require: 'rack/cors' gem 'rack-cors', require: 'rack/cors'
# Email validation
gem "email_validator", "~> 1.4.0", :require => 'email_validator/strict'
# Format dates and times # Format dates and times
# based on human-friendly examples # based on human-friendly examples
gem "stamp" gem "stamp"
......
...@@ -110,8 +110,6 @@ GEM ...@@ -110,8 +110,6 @@ GEM
email_spec (1.5.0) email_spec (1.5.0)
launchy (~> 2.1) launchy (~> 2.1)
mail (~> 2.2) mail (~> 2.2)
email_validator (1.4.0)
activemodel
emoji (1.0.1) emoji (1.0.1)
json json
enumerize (0.7.0) enumerize (0.7.0)
...@@ -591,7 +589,6 @@ DEPENDENCIES ...@@ -591,7 +589,6 @@ DEPENDENCIES
diffy (~> 3.0.3) diffy (~> 3.0.3)
dropzonejs-rails dropzonejs-rails
email_spec email_spec
email_validator (~> 1.4.0)
enumerize enumerize
factory_girl_rails factory_girl_rails
ffaker ffaker
......
# Based on https://github.com/balexand/email_validator
#
# Extended to use only strict mode with following allowed characters:
# ' - apostrophe
#
# See http://www.remote.org/jochen/mail/info/chars.html
#
class EmailValidator < ActiveModel::EachValidator
@@default_options = {}
def self.default_options
@@default_options
end
def validate_each(record, attribute, value)
options = @@default_options.merge(self.options)
unless value =~ /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i
record.errors.add(attribute, options[:message] || :invalid)
end
end
end
...@@ -83,11 +83,17 @@ describe User do ...@@ -83,11 +83,17 @@ describe User do
user = build(:user, email: 'info@example.com') user = build(:user, email: 'info@example.com')
expect(user).to be_valid expect(user).to be_valid
end end
it 'accepts info+test@example.com' do it 'accepts info+test@example.com' do
user = build(:user, email: 'info+test@example.com') user = build(:user, email: 'info+test@example.com')
expect(user).to be_valid expect(user).to be_valid
end end
it "accepts o'reilly@example.com" do
user = build(:user, email: "o'reilly@example.com")
expect(user).to be_valid
end
it 'rejects test@test@example.com' do it 'rejects test@test@example.com' do
user = build(:user, email: 'test@test@example.com') user = build(:user, email: 'test@test@example.com')
expect(user).to be_invalid expect(user).to be_invalid
...@@ -97,6 +103,11 @@ describe User do ...@@ -97,6 +103,11 @@ describe User do
user = build(:user, email: 'mailto:test@example.com') user = build(:user, email: 'mailto:test@example.com')
expect(user).to be_invalid expect(user).to be_invalid
end end
it "rejects lol!'+=?><#$%^&*()@gmail.com" do
user = build(:user, email: "lol!'+=?><#$%^&*()@gmail.com")
expect(user).to be_invalid
end
end end
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment