Merge pull request #3320 from betagouv/fix-search-special-chars

search: exclude more special characters
This commit is contained in:
Pierre de La Morinerie 2019-01-23 16:02:21 +01:00 committed by GitHub
commit 75b6eaca53
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View file

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

View file

@ -90,5 +90,11 @@ describe DossierSearchService do
it { expect(subject.size).to eq(1) }
end
describe 'search with characters disallowed by the tsquery parser' do
let(:terms) { "'?\\:&!(OCTO) <plop>" }
it { expect(subject.size).to eq(1) }
end
end
end