diff --git a/lib/search.rb b/lib/search.rb index 91a8d45e431..6f553a49457 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -129,6 +129,8 @@ class Search # Removes any zero-width characters from search terms term.to_s.gsub!(/[\u200B-\u200D\uFEFF]/, '') + # Replace curly quotes to regular quotes + term.to_s.gsub!(/[\u201c\u201d]/, '"') @clean_term = term.to_s.dup term = process_advanced_search!(term) diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 3576cb6a608..3898b38fd6e 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -71,6 +71,17 @@ describe Search do expect(search.clean_term).to eq('capybara') end + it 'replaces curly quotes to regular quotes in search terms' do + term = '“discourse”' + + expect(term == '"discourse"').to eq(false) + + search = Search.new(term) + expect(search.valid?).to eq(true) + expect(search.term).to eq('"discourse"') + expect(search.clean_term).to eq('"discourse"') + end + it 'does not search when the search term is too small' do search = Search.new('evil', min_search_term_length: 5) search.execute