diff options
| author | cedricnjanga | 2017-12-12 17:11:55 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-12-13 11:54:26 +0100 |
| commit | 5404d56ece41ec949f142457f161c7b9663dd5fc (patch) | |
| tree | bb8b9acaf122d562dd4b9e5862a14a42bbd006d1 | |
| parent | 9b3c1234644adb51e24e6d664d63ff37a7bc9fa2 (diff) | |
| download | chouette-core-5404d56ece41ec949f142457f161c7b9663dd5fc.tar.bz2 | |
Refs # 5256 Change Ransack initializer to escape wildcard on queries
| -rw-r--r-- | config/initializers/ransack.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/config/initializers/ransack.rb b/config/initializers/ransack.rb index 659ee4a79..09d895e47 100644 --- a/config/initializers/ransack.rb +++ b/config/initializers/ransack.rb @@ -4,6 +4,7 @@ Ransack.configure do |config| formatter: proc { |v| v.split(' to ') }, type: :string end + module Arel module Predications def between other @@ -11,3 +12,19 @@ module Arel end end end + +module Ransack + module Constants + module_function + # replace % \ to \% \\ + def escape_wildcards(unescaped) + case ActiveRecord::Base.connection.adapter_name + when "Mysql2".freeze, "PostgreSQL".freeze, "PostGIS".freeze + # Necessary for PostgreSQL and MySQL + unescaped.to_s.gsub(/([\\|\%|_|.])/, '\\\\\\1') + else + unescaped + end + end + end +end |
