Merge pull request #1013 from daflip/dont-escape-periods-in-mysql2

Don't escape period characters with wildcard searches in mysql2
This commit is contained in:
Sean 2019-06-05 21:49:01 +02:00 committed by GitHub
commit 7836838a07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 4 deletions

View File

@ -102,8 +102,11 @@ module Ransack
# replace % \ to \% \\
def escape_wildcards(unescaped)
case ActiveRecord::Base.connection.adapter_name
when "Mysql2".freeze, "PostgreSQL".freeze
# Necessary for PostgreSQL and MySQL
when "Mysql2".freeze
# Necessary for MySQL
unescaped.to_s.gsub(/([\\%_])/, '\\\\\\1')
when "PostgreSQL".freeze
# Necessary for PostgreSQL
unescaped.to_s.gsub(/([\\%_.])/, '\\\\\\1')
else
unescaped

View File

@ -126,7 +126,7 @@ module Ransack
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
/"people"."name" ILIKE '%\\%\\.\\_\\\\%'/
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
/`people`.`name` LIKE '%\\\\%\\\\.\\\\_\\\\\\\\%'/
/`people`.`name` LIKE '%\\\\%.\\\\_\\\\\\\\%'/
else
/"people"."name" LIKE '%%._\\%'/
end) do
@ -145,7 +145,7 @@ module Ransack
(if ActiveRecord::Base.connection.adapter_name == "PostgreSQL"
/"people"."name" NOT ILIKE '%\\%\\.\\_\\\\%'/
elsif ActiveRecord::Base.connection.adapter_name == "Mysql2"
/`people`.`name` NOT LIKE '%\\\\%\\\\.\\\\_\\\\\\\\%'/
/`people`.`name` NOT LIKE '%\\\\%.\\\\_\\\\\\\\%'/
else
/"people"."name" NOT LIKE '%%._\\%'/
end) do