I am following along with the book Beginning Rails 4.
There appears to be a mistake in Chapter 6 related to this:
"A common pitfall in Ruby's regular expressions is to match the string's beginning and end by ^
and $
, instead of \A
and \z
."
Which I saw here: http://guides.rubyonrails.org/security.html#regular-expressions
In particular, there is a User model with an email attribute, the format of which the book says to validate with:
validates_format_of :email, :with => /^[^@][\w.-]+@[\w.-]+[.][a-z]{2,4}$/i
The format validator raises an exception:
ArgumentError: The provided regular expression is using multiline anchors (^ or $), which may present a security risk. Did you mean to use \A and \z, or forgot to add the :multiline => true option?
I just want to make sure: this is precisely the case where using ^
and $
is a security threat, right?
If so, I can substitute ^
and $
with \A
and \z
.
But how would I use the :multiline => true
option in this case?