rails/rails — pull request #14806 by petRUShka (2014-04-18 21:28:02+00:00)
Title: Fixed sanitize_sql_like to escape parentheses

There is a problem with sanitising `LIKE` statement If there is a parentheses in it it can cause error like this in real Rails app:

Street Load (3.5ms) SELECT `streets`.* FROM `streets` WHERE (name LIKE '%(%')
Completed 500 Internal Server Error in 18ms

RegexpError (end pattern with unmatched parenthesis: /(/):

See corresponding [SO question](http://stackoverflow.com/questions/23158150/proper-escape-like-conditions#23158150).

Pull request adding parentheses to list of escaping symbols and fix that problem.

Example:

class Street
def self.search(term)
where("title LIKE ?", sanitize_sql_like(term))
end
end

Street.search("(20% _reduction_)")
# => Query looks like "... title LIKE '\(20\% \_reduction\_\)' ..."