From e57fdc1190af582544154b77f0271ef9f206bc47 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 11 Jun 2014 13:04:30 +0200 Subject: Remove email_validator gem and allow apostrophe as a valid character in email. --- Gemfile | 3 --- Gemfile.lock | 3 --- lib/gitlab/email_validator.rb | 21 +++++++++++++++++++++ 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 lib/gitlab/email_validator.rb diff --git a/Gemfile b/Gemfile index 5b45b8bdcc2..719d65a2eb9 100644 --- a/Gemfile +++ b/Gemfile @@ -50,9 +50,6 @@ gem "grape", "~> 0.6.1" gem "grape-entity", "~> 0.4.2" gem 'rack-cors', require: 'rack/cors' -# Email validation -gem "email_validator", "~> 1.4.0", :require => 'email_validator/strict' - # Format dates and times # based on human-friendly examples gem "stamp" diff --git a/Gemfile.lock b/Gemfile.lock index 0d13ed5884c..9e4dd359651 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -110,8 +110,6 @@ GEM email_spec (1.5.0) launchy (~> 2.1) mail (~> 2.2) - email_validator (1.4.0) - activemodel emoji (1.0.1) json enumerize (0.7.0) @@ -591,7 +589,6 @@ DEPENDENCIES diffy (~> 3.0.3) dropzonejs-rails email_spec - email_validator (~> 1.4.0) enumerize factory_girl_rails ffaker diff --git a/lib/gitlab/email_validator.rb b/lib/gitlab/email_validator.rb new file mode 100644 index 00000000000..0a67ebcd795 --- /dev/null +++ b/lib/gitlab/email_validator.rb @@ -0,0 +1,21 @@ +# 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 -- cgit v1.2.1 From f43e41973f912588d7af23a5575ede94a88d3a5d Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 11 Jun 2014 13:22:56 +0200 Subject: Test for the apostrophe in the email --- lib/email_validator.rb | 21 +++++++++++++++++++++ lib/gitlab/email_validator.rb | 21 --------------------- spec/models/user_spec.rb | 11 +++++++++++ 3 files changed, 32 insertions(+), 21 deletions(-) create mode 100644 lib/email_validator.rb delete mode 100644 lib/gitlab/email_validator.rb diff --git a/lib/email_validator.rb b/lib/email_validator.rb new file mode 100644 index 00000000000..0a67ebcd795 --- /dev/null +++ b/lib/email_validator.rb @@ -0,0 +1,21 @@ +# 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 diff --git a/lib/gitlab/email_validator.rb b/lib/gitlab/email_validator.rb deleted file mode 100644 index 0a67ebcd795..00000000000 --- a/lib/gitlab/email_validator.rb +++ /dev/null @@ -1,21 +0,0 @@ -# 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 diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 34a5bcfb4a5..4e0ebb584d1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -83,11 +83,17 @@ describe User do user = build(:user, email: 'info@example.com') expect(user).to be_valid end + it 'accepts info+test@example.com' do user = build(:user, email: 'info+test@example.com') expect(user).to be_valid 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 user = build(:user, email: 'test@test@example.com') expect(user).to be_invalid @@ -97,6 +103,11 @@ describe User do user = build(:user, email: 'mailto:test@example.com') expect(user).to be_invalid end + + it "rejects lol!'+=?><#$%^&*()@gmail.com" do + user = build(:user, email: "lol!'+=?><#$%^&*()@gmail.com") + expect(user).to be_invalid + end end end -- cgit v1.2.1