Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(email_validator): handle trailing whitespace in emails #255

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/valid_email2/email_validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions spec/valid_email2_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ class TestUserMultiple < TestModel
user = TestUser.new(email: "[email protected]")
expect(user.valid?).to be_falsy
end

it "is invalid with trailing whitespace" do
user = TestUser.new(email: "[email protected] ")
expect(user.valid?).to be_falsey
end
end

describe "with disposable validation" do
Expand Down
Loading