fix for searches with two apostrophes

This commit is contained in:
Peter Bhat Harkins 2023-09-14 09:38:08 -05:00
parent 46c343a956
commit f467d5e943
2 changed files with 5 additions and 4 deletions

View File

@ -105,9 +105,9 @@ class Search
when :negated
# TODO
when :quoted
terms.append '"' + strip_operators(value).gsub("'", "\\'") + '"'
terms.append '"' + strip_operators(value).gsub("'", "\\\\'") + '"'
when :term
val = strip_operators(value).gsub("'", "\\'")
val = strip_operators(value).gsub("'", "\\\\'")
# if punctuation is replaced with a space, this would generate a terms search
# AGAINST('+' in boolean mode)
terms.append val if !val.empty?
@ -178,9 +178,9 @@ class Search
when :negated
# TODO
when :quoted
terms.append '"' + strip_operators(value).gsub("'", "\\'") + '"'
terms.append '"' + strip_operators(value).gsub("'", "\\\\'") + '"'
when :term
val = strip_operators(value).gsub("'", "\\'")
val = strip_operators(value).gsub("'", "\\\\'")
# if punctuation is replaced with a space, this would generate a terms search
# AGAINST('+' in boolean mode)
terms.append val if !val.empty?

View File

@ -85,6 +85,7 @@ describe Search do
{what: "stories", q: "term", order: "newest#{esc}"},
{what: "stories", q: "term", page: "2#{esc}"},
{what: "stories#{esc}", q: "term"},
{what: "stories", q: "term 'two apostrophes'"},
# comments
{what: "comments", q: "term#{esc}"},
{what: "comments", q: "\"term#{esc}\""},