mirror of
https://github.com/discourse/discourse.git
synced 2025-05-21 18:12:32 +08:00
DEV: pull email address validation out to a new EmailAddressValidator
We validate the *format* of email addresses in many places with a match against a regex, often with very slightly different syntax. Adding a separate EmailAddressValidator simplifies the code in a few spots and feels cleaner. Deprecated the old location in case someone is using it in a plugin. No functionality change is in this commit. Note: the regex used at the moment does not support using address literals, e.g.: * localpart@[192.168.0.1] * localpart@[2001:db8::1]
This commit is contained in:

committed by
Michael Brown

parent
e54b70460e
commit
3bf3b9a4a5
@ -320,7 +320,7 @@ class ImportScripts::Base
|
||||
opts[:username] = UserNameSuggester.suggest(opts[:username].presence || opts[:name].presence || opts[:email])
|
||||
end
|
||||
|
||||
unless opts[:email][EmailValidator.email_regex]
|
||||
if !EmailAddressValidator.valid_value?(opts[:email])
|
||||
opts[:email] = fake_email
|
||||
puts "Invalid email '#{original_email}' for '#{opts[:username]}'. Using '#{opts[:email]}'"
|
||||
end
|
||||
|
@ -76,7 +76,7 @@ class ImportScripts::Drupal < ImportScripts::Base
|
||||
|
||||
create_users(users, total: user_count, offset: offset) do |user|
|
||||
email = user["email"].presence || fake_email
|
||||
email = fake_email unless email[EmailValidator.email_regex]
|
||||
email = fake_email if !EmailAddressValidator.valid_value?(email)
|
||||
|
||||
username = @htmlentities.decode(user["username"]).strip
|
||||
|
||||
|
@ -151,7 +151,7 @@ EOM
|
||||
|
||||
create_users(users, total: user_count, offset: offset) do |user|
|
||||
email = user["email"].presence || fake_email
|
||||
email = fake_email unless email[EmailValidator.email_regex]
|
||||
email = fake_email if !EmailAddressValidator.valid_value?(email)
|
||||
|
||||
password = [user["password"].presence, user["salt"].presence].compact.join(":")
|
||||
|
||||
|
Reference in New Issue
Block a user