A platform for community discussion. Free, open, simple.
FIX: Replace all quote-like unicodes with quotes (#19714)
Bianca Nenciufb780c50fd85
diff --git a/lib/search.rb b/lib/search.rbindex 95e1c69fe67..e81b7ab0d93 100644--- a/lib/search.rb+++ b/lib/search.rb@@ -1230,9 +1230,11 @@ class Searchenddef self.escape_string(term)- # HACK: The ’ has to be "unaccented" before it is escaped or the resulting- # tsqueries will be invalid- term = term.gsub("\u{2019}", "'") if SiteSetting.search_ignore_accents+ # HACK: The ’ and other similar characters have to be "unaccented" before+ # it is escaped or the resulting tsqueries will be invalid+ if SiteSetting.search_ignore_accents+ term = term.gsub(/[\u02b9\u02bb\u02bc\u02bd\u02c8\u2018\u2019\u201b\u2032\uff07]/, "'")+ endPG::Connection.escape_string(term).gsub('\\', '\\\\\\')enddiff --git a/spec/models/topic_spec.rb b/spec/models/topic_spec.rbindex d60f7b83db7..4db4f3a5546 100644--- a/spec/models/topic_spec.rb+++ b/spec/models/topic_spec.rb@@ -645,6 +645,12 @@ RSpec.describe Topic doexpect(Topic.similar_to("怎么上自己的", "")).to eq([])end+ it "does not result in invalid statement when title contains unicode characters" do+ SiteSetting.search_ignore_accents = true++ expect(Topic.similar_to("'bad quotes'", "'bad quotes'")).to eq([])+ end+context "with a similar topic" dofab!(:post) doSearchIndexer.enable