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 | 50 | gem "grape-entity", "~> 0.4.2" |
51 | 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 | 53 | # Format dates and times |
57 | 54 | # based on human-friendly examples |
58 | 55 | gem "stamp" | ... | ... |
Gemfile.lock
... | ... | @@ -110,8 +110,6 @@ GEM |
110 | 110 | email_spec (1.5.0) |
111 | 111 | launchy (~> 2.1) |
112 | 112 | mail (~> 2.2) |
113 | - email_validator (1.4.0) | |
114 | - activemodel | |
115 | 113 | emoji (1.0.1) |
116 | 114 | json |
117 | 115 | enumerize (0.7.0) |
... | ... | @@ -591,7 +589,6 @@ DEPENDENCIES |
591 | 589 | diffy (~> 3.0.3) |
592 | 590 | dropzonejs-rails |
593 | 591 | email_spec |
594 | - email_validator (~> 1.4.0) | |
595 | 592 | enumerize |
596 | 593 | factory_girl_rails |
597 | 594 | ffaker | ... | ... |
... | ... | @@ -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 | 83 | user = build(:user, email: 'info@example.com') |
84 | 84 | expect(user).to be_valid |
85 | 85 | end |
86 | + | |
86 | 87 | it 'accepts info+test@example.com' do |
87 | 88 | user = build(:user, email: 'info+test@example.com') |
88 | 89 | expect(user).to be_valid |
89 | 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 | 97 | it 'rejects test@test@example.com' do |
92 | 98 | user = build(:user, email: 'test@test@example.com') |
93 | 99 | expect(user).to be_invalid |
... | ... | @@ -97,6 +103,11 @@ describe User do |
97 | 103 | user = build(:user, email: 'mailto:test@example.com') |
98 | 104 | expect(user).to be_invalid |
99 | 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 | 111 | end |
101 | 112 | end |
102 | 113 | ... | ... |