fix to_tsquery disallowed chars

This commit is contained in:
clemkeirua 2020-04-20 14:27:43 +02:00
parent 8320c66414
commit 2d68d7dc59
2 changed files with 7 additions and 1 deletions

View file

@ -62,8 +62,8 @@ class DossierSearchService
def self.to_tsquery(search_terms)
(search_terms || "")
.strip
.gsub(/['?\\:&|!<>\(\)]/, "") # drop disallowed characters
.strip
.split(/\s+/) # split words
.map { |x| "#{x}:*" } # enable prefix matching
.join(" & ")

View file

@ -198,5 +198,11 @@ describe DossierSearchService do
it { expect(subject.size).to eq(1) }
end
describe 'search with a single forbidden character should not crash postgres' do
let(:terms) { '? OCTO' }
it { expect(subject.size).to eq(3) }
end
end
end