Commit 1d7735773e44e25d91a2cb2111877465ddae4366
Exists in
spb-stable
and in
2 other branches
Merge branch 'email_with_apostrophe' into 'master'
Email with apostrophe Fixes #1225
Showing
4 changed files
with
32 additions
and
6 deletions
Show diff stats
Gemfile
@@ -50,9 +50,6 @@ gem "grape", "~> 0.6.1" | @@ -50,9 +50,6 @@ gem "grape", "~> 0.6.1" | ||
50 | gem "grape-entity", "~> 0.4.2" | 50 | gem "grape-entity", "~> 0.4.2" |
51 | gem 'rack-cors', require: 'rack/cors' | 51 | gem 'rack-cors', require: 'rack/cors' |
52 | 52 | ||
53 | -# Email validation | ||
54 | -gem "email_validator", "~> 1.4.0", :require => 'email_validator/strict' | ||
55 | - | ||
56 | # Format dates and times | 53 | # Format dates and times |
57 | # based on human-friendly examples | 54 | # based on human-friendly examples |
58 | gem "stamp" | 55 | gem "stamp" |
Gemfile.lock
@@ -110,8 +110,6 @@ GEM | @@ -110,8 +110,6 @@ GEM | ||
110 | email_spec (1.5.0) | 110 | email_spec (1.5.0) |
111 | launchy (~> 2.1) | 111 | launchy (~> 2.1) |
112 | mail (~> 2.2) | 112 | mail (~> 2.2) |
113 | - email_validator (1.4.0) | ||
114 | - activemodel | ||
115 | emoji (1.0.1) | 113 | emoji (1.0.1) |
116 | json | 114 | json |
117 | enumerize (0.7.0) | 115 | enumerize (0.7.0) |
@@ -591,7 +589,6 @@ DEPENDENCIES | @@ -591,7 +589,6 @@ DEPENDENCIES | ||
591 | diffy (~> 3.0.3) | 589 | diffy (~> 3.0.3) |
592 | dropzonejs-rails | 590 | dropzonejs-rails |
593 | email_spec | 591 | email_spec |
594 | - email_validator (~> 1.4.0) | ||
595 | enumerize | 592 | enumerize |
596 | factory_girl_rails | 593 | factory_girl_rails |
597 | ffaker | 594 | ffaker |
@@ -0,0 +1,21 @@ | @@ -0,0 +1,21 @@ | ||
1 | +# Based on https://github.com/balexand/email_validator | ||
2 | +# | ||
3 | +# Extended to use only strict mode with following allowed characters: | ||
4 | +# ' - apostrophe | ||
5 | +# | ||
6 | +# See http://www.remote.org/jochen/mail/info/chars.html | ||
7 | +# | ||
8 | +class EmailValidator < ActiveModel::EachValidator | ||
9 | + @@default_options = {} | ||
10 | + | ||
11 | + def self.default_options | ||
12 | + @@default_options | ||
13 | + end | ||
14 | + | ||
15 | + def validate_each(record, attribute, value) | ||
16 | + options = @@default_options.merge(self.options) | ||
17 | + unless value =~ /\A\s*([-a-z0-9+._']{1,64})@((?:[-a-z0-9]+\.)+[a-z]{2,})\s*\z/i | ||
18 | + record.errors.add(attribute, options[:message] || :invalid) | ||
19 | + end | ||
20 | + end | ||
21 | +end |
spec/models/user_spec.rb
@@ -83,11 +83,17 @@ describe User do | @@ -83,11 +83,17 @@ describe User do | ||
83 | user = build(:user, email: 'info@example.com') | 83 | user = build(:user, email: 'info@example.com') |
84 | expect(user).to be_valid | 84 | expect(user).to be_valid |
85 | end | 85 | end |
86 | + | ||
86 | it 'accepts info+test@example.com' do | 87 | it 'accepts info+test@example.com' do |
87 | user = build(:user, email: 'info+test@example.com') | 88 | user = build(:user, email: 'info+test@example.com') |
88 | expect(user).to be_valid | 89 | expect(user).to be_valid |
89 | end | 90 | end |
90 | 91 | ||
92 | + it "accepts o'reilly@example.com" do | ||
93 | + user = build(:user, email: "o'reilly@example.com") | ||
94 | + expect(user).to be_valid | ||
95 | + end | ||
96 | + | ||
91 | it 'rejects test@test@example.com' do | 97 | it 'rejects test@test@example.com' do |
92 | user = build(:user, email: 'test@test@example.com') | 98 | user = build(:user, email: 'test@test@example.com') |
93 | expect(user).to be_invalid | 99 | expect(user).to be_invalid |
@@ -97,6 +103,11 @@ describe User do | @@ -97,6 +103,11 @@ describe User do | ||
97 | user = build(:user, email: 'mailto:test@example.com') | 103 | user = build(:user, email: 'mailto:test@example.com') |
98 | expect(user).to be_invalid | 104 | expect(user).to be_invalid |
99 | end | 105 | end |
106 | + | ||
107 | + it "rejects lol!'+=?><#$%^&*()@gmail.com" do | ||
108 | + user = build(:user, email: "lol!'+=?><#$%^&*()@gmail.com") | ||
109 | + expect(user).to be_invalid | ||
110 | + end | ||
100 | end | 111 | end |
101 | end | 112 | end |
102 | 113 |