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

CodeQuality: Lengthen TLD wildcard matching for regex / repair #13

Merged
merged 1 commit into from Aug 2, 2017
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/email_repair/constants.rb
Expand Up @@ -4,7 +4,7 @@ class << self
def email_regex
local_part_regex = "[#{valid_chars}]" \
"([#{valid_chars_with_dot}]*[#{valid_chars}])?"
/#{local_part_regex}@(?:[a-z0-9\-]+\.)+(?:museum|travel|[a-z]{2,4})/
/#{local_part_regex}@(?:[a-z0-9\-]+\.)+(?:[a-z]{2,24})/
end

private
Expand Down
2 changes: 1 addition & 1 deletion lib/email_repair/mechanic.rb
Expand Up @@ -45,7 +45,7 @@ def self.repair(email)
.gsub(/\s/, '')
.sub(/@+/, '@')
.sub(/\.c0m$/, '.com')
.sub(/,[a-z]{2,4}$/) { |m| m.sub(',', '.') }
.sub(/,[a-z]{2,24}$/) { |m| m.sub(',', '.') }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to have a more precise check at some point, but this will do.

end
end

Expand Down
5 changes: 5 additions & 0 deletions spec/lib/email_repair/mechanic_spec.rb
Expand Up @@ -32,12 +32,17 @@ module EmailRepair
it 'returns clean emails as is' do
# Rant about apostrophe in email
# http://www.stuffaboutcode.com/2013/02/validating-email-address-bloody.html
# List of longest TLDs
# https://jasontucker.blog/8945/what-is-the-longest-tld-you-can-get-for-a-domain-name
good_emails = %w(
b@b.com
lobatifricha@gmail.com
mrspicy+whocares@whatevs.com
your.mom@the.museum
martin.o'hanlon@mycompany.com
b@mps.school
b@kickstarter.engineering
b@joyful.christmas
)

good_emails.each do |good_email|
Expand Down