FIX: Ignore empty search terms in topic queries

Previously an empty search term would cause an invalid tsquery, and led to a 500 error. Now an empty string will be ignored.
This commit is contained in:
David Taylor 2020-09-10 15:49:11 +01:00
parent 53ffbc8d6e
commit 2f96474155
No known key found for this signature in database
GPG Key ID: 46904C18B1D3F434
2 changed files with 4 additions and 1 deletions

View File

@ -748,7 +748,7 @@ class TopicQuery
result = result.where('topics.id in (?)', options[:topic_ids]).references(:topics)
end
if search = options[:search]
if search = options[:search].presence
result = result.where("topics.id in (select pp.topic_id from post_search_data pd join posts pp on pp.id = pd.post_id where pd.search_data @@ #{Search.ts_query(term: search.to_s)})")
end

View File

@ -52,6 +52,9 @@ RSpec.describe ListController do
get "/latest.json?page=2147483647"
expect(response.status).to eq(200)
get "/latest?search="
expect(response.status).to eq(200)
end
(Discourse.anonymous_filters - [:categories]).each do |filter|