Commit e447db1bc7f8ca126e77b725610b4499449edd2a
1 parent
0a9bfdd2
Exists in
master
and in
17 other branches
Ensure escaped like works correctly
Showing
3 changed files
with
8 additions
and
1 deletions
Show diff stats
CHANGELOG.md
lib/searchkick/query.rb
... | ... | @@ -936,7 +936,7 @@ module Searchkick |
936 | 936 | } |
937 | 937 | } |
938 | 938 | when :like |
939 | - regex = Regexp.escape(op_value).gsub("%", ".*").gsub("_", ".") | |
939 | + regex = Regexp.escape(op_value).gsub(/(?<!\\)%/, ".*").gsub(/(?<!\\)_/, ".").gsub("\\%", "%").gsub("\\_", "_") | |
940 | 940 | filters << {regexp: {field => {value: regex}}} |
941 | 941 | when :prefix |
942 | 942 | filters << {prefix: {field => op_value}} | ... | ... |
test/where_test.rb
... | ... | @@ -138,6 +138,11 @@ class WhereTest < Minitest::Test |
138 | 138 | assert_search "product", ["Product ABC"], where: {name: {like: "Product_ABC"}} |
139 | 139 | end |
140 | 140 | |
141 | + def test_like_escape | |
142 | + store_names ["Product 100%", "Product B"] | |
143 | + assert_search "product", ["Product 100%"], where: {name: {like: "% 100\\%"}} | |
144 | + end | |
145 | + | |
141 | 146 | # def test_script |
142 | 147 | # store [ |
143 | 148 | # {name: "Product A", store_id: 1}, | ... | ... |