diff --git a/lib/valid_email2/email_validator.rb b/lib/valid_email2/email_validator.rb index d96e772..812f328 100644 --- a/lib/valid_email2/email_validator.rb +++ b/lib/valid_email2/email_validator.rb @@ -57,12 +57,12 @@ def sanitized_values(input) options = default_options.merge(self.options) if options[:multiple] - email_list = input.is_a?(Array) ? input : input.split(',') + email_list = input.is_a?(Array) ? input : input.split(',').map(&:strip) else email_list = [input] end - email_list.reject(&:empty?).map(&:strip) + email_list.reject(&:empty?) end def error(record, attribute) diff --git a/spec/valid_email2_spec.rb b/spec/valid_email2_spec.rb index c1c1a3a..58b8543 100644 --- a/spec/valid_email2_spec.rb +++ b/spec/valid_email2_spec.rb @@ -158,6 +158,11 @@ class TestUserMultiple < TestModel user = TestUser.new(email: "foo@gmail-.com") expect(user.valid?).to be_falsy end + + it "is invalid with trailing whitespace" do + user = TestUser.new(email: "foo@example.com ") + expect(user.valid?).to be_falsey + end end describe "with disposable validation" do