Merge pull request #3897 from Keirua/fix/crash-empty-query-search

no crash when q is missing on RechercheController::index
This commit is contained in:
Keirua 2019-05-22 15:03:31 +02:00 committed by GitHub
commit ce5ee0b766
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

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

View file

@ -48,5 +48,16 @@ describe Gestionnaires::RechercheController, type: :controller do
end
end
end
context 'with no query param it does not crash' do
subject { get :index, params: {} }
it { is_expected.to have_http_status(200) }
it 'returns 0 dossier' do
subject
expect(assigns(:dossiers).count).to eq(0)
end
end
end
end