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: Change email validation regex [PT-187054507] #1239

Merged
merged 1 commit into from
Feb 15, 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
2 changes: 1 addition & 1 deletion rails/app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def self.name_regex

email_name_regex = '[\w\.%\+\-\']+'.freeze
domain_head_regex = '(?:[A-Z0-9\-]+\.)+'.freeze
domain_tld_regex = '(?:[A-Z]{2}|com|org|net|edu|gov|mil|biz|info|mobi|name|aero|jobs|museum)'.freeze
domain_tld_regex = '(?:[A-Z]{2,})'.freeze
email_regex = /\A#{email_name_regex}@#{domain_head_regex}#{domain_tld_regex}\z/i
bad_email_message = "should look like an email address.".freeze

Expand Down
4 changes: 2 additions & 2 deletions rails/spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
['foo@bar.com', 'foo@newskool-tld.museum', 'foo@twoletter-tld.de', 'foo@nonexistant-tld.qq',
'r@a.wk', '1234567890-234567890-234567890-234567890-234567890-234567890-234567890-234567890-234567890@gmail.com',
'hello.-_there@funnychar.com', 'uucp%addr@gmail.com', 'hello+routing-str@gmail.com',
'domain@can.haz.many.sub.doma.in', 'student.name@university.edu'
'domain@can.haz.many.sub.doma.in', 'student.name@university.edu', 'foo@anytld.xxx', 'foo@longtld.abcdefg', 'teacher@some.school'
].each do |email_str|
it "'#{email_str}'" do
expect do
Expand All @@ -103,7 +103,7 @@
end

describe 'disallows illegitimate emails' do
['!!@nobadchars.com', 'foo@no-rep-dots..com', 'foo@badtld.xxx', 'foo@toolongtld.abcdefg',
['!!@nobadchars.com', 'foo@no-rep-dots..com', 'needdomain@', 'needtld@example', '@.com', '@example.com', 'oneletterltd@example.x',
'Iñtërnâtiônàlizætiøn@hasnt.happened.to.email', 'need.domain.and.tld@de',
'r@.wk', '1234567890-234567890-234567890-234567890-234567890-234567890-234567890-234567890-234567890@gmail2.com',
# these are technically allowed but not seen in practice:
Expand Down
Loading