diff options
author | Xavier Noria <fxn@hashref.com> | 2016-07-24 21:33:27 +0200 |
---|---|---|
committer | Xavier Noria <fxn@hashref.com> | 2016-07-24 21:42:19 +0200 |
commit | 11b463d8cbacfe2cc1662f9e314440de71806ca9 (patch) | |
tree | dbb0765705d70811e5db149edf0e01ff675a4c0d /activemodel | |
parent | 95b2a6abc7c9ac46ddbabe96a26e280f25a78aa7 (diff) | |
download | rails-11b463d8cbacfe2cc1662f9e314440de71806ca9.tar.gz rails-11b463d8cbacfe2cc1662f9e314440de71806ca9.tar.bz2 rails-11b463d8cbacfe2cc1662f9e314440de71806ca9.zip |
use \A and \z when you mean \A and \z
In Ruby ^ and $ mean start and end of *line*.
A regexp that validates an email should not check if
some line of the string looks like an email, and maybe
be surrounded by the entire Joyce's Ulysses. What the
regexp has to check is if the string itself looks like
an email.
This validator is used only in tests, the ^/$ anchors
implied no risk.
Diffstat (limited to 'activemodel')
-rw-r--r-- | activemodel/test/validators/email_validator.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/activemodel/test/validators/email_validator.rb b/activemodel/test/validators/email_validator.rb index dda0c4773c..5dc1fc5ae2 100644 --- a/activemodel/test/validators/email_validator.rb +++ b/activemodel/test/validators/email_validator.rb @@ -3,6 +3,6 @@ require 'active_support/core_ext/regexp' class EmailValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) record.errors[attribute] << (options[:message] || "is not an email") unless - /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i.match?(value) + /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i.match?(value) end end |