ruby on rails - Regular expressions with validations in RoR 4 -


there following code:

class product < activerecord::base   validates :title, :description, :image_url, presence: true   validates :price, numericality: {greater_than_or_equal_to: 0.01}   validates :title, uniqueness: true   validates :image_url, allow_blank: true, format: {       with: %r{\.(gif|jpg|png)$}i,       message: 'url must point git/jpg/png pictures'   } end 

it works, when try test using "rake test" i'll catch message:

rake aborted! provided regular expression using multiline anchors (^ or $), may present security risk. did mean use \a , \z, or forgot add :multiline => true option? 

what mean? how can fix it?

^ , $ start of line , end of line anchors. while \a , \z permanent start of string , end of string anchors.
see difference:

string = "abcde\nzzzz" # => "abcde\nzzzz"  /^abcde$/ === string # => true  /\aabcde\z/ === string # => false 

so rails telling you, "are sure want use ^ , $? don't want use \a , \z instead?"

there more on rails security concern generates warning here.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -