refactored tsquery sql to use rails escaping mechanisms
This commit is contained in:
@@ -5,6 +5,14 @@ module Danbooru
|
||||
return self.gsub(/\\/, '\0\0').gsub(/(%|_)/, "\\\\\\1").gsub(/\*/, '%')
|
||||
end
|
||||
|
||||
def to_escaped_for_tsquery_split
|
||||
scan(/\S+/).map {|x| x.to_escaped_for_tsquery}.join(" & ")
|
||||
end
|
||||
|
||||
def to_escaped_for_tsquery
|
||||
"'#{gsub(/\\|'/, '\0\0\0\0')}'"
|
||||
end
|
||||
|
||||
def to_escaped_js
|
||||
return self.gsub(/\\/, '\0\0').gsub(/['"]/) {|m| "\\#{m}"}.gsub(/\r\n|\r|\n/, '\\n')
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user