mirror of
https://github.com/discourse/discourse.git
synced 2025-03-06 03:09:43 +00:00
FIX: prevents crash in discourse_tagging with empty term (#8548)
This commit is contained in:
parent
6ab12ed96b
commit
81b4de39ee
@ -222,7 +222,7 @@ module DiscourseTagging
|
||||
|
||||
distinct_clause = if opts[:order_popularity]
|
||||
"DISTINCT ON (topic_count, name)"
|
||||
elsif opts[:order_search_results]
|
||||
elsif opts[:order_search_results] && opts[:term].present?
|
||||
"DISTINCT ON (lower(name) = lower(:cleaned_term), topic_count, name)"
|
||||
else
|
||||
""
|
||||
@ -278,9 +278,7 @@ module DiscourseTagging
|
||||
|
||||
term = opts[:term]
|
||||
if term.present?
|
||||
term = term.gsub("_", "\\_")
|
||||
clean_tag(term)
|
||||
term.downcase!
|
||||
term = term.gsub("_", "\\_").downcase
|
||||
builder.where("LOWER(name) LIKE :term")
|
||||
builder_params[:cleaned_term] = term
|
||||
builder_params[:term] = "%#{term}%"
|
||||
|
@ -129,6 +129,16 @@ describe DiscourseTagging do
|
||||
end
|
||||
end
|
||||
|
||||
context 'empty term' do
|
||||
it "works with an empty term" do
|
||||
tags = DiscourseTagging.filter_allowed_tags(Guardian.new(user),
|
||||
term: '',
|
||||
order_search_results: true
|
||||
).map(&:name)
|
||||
expect(sorted_tag_names(tags)).to eq(sorted_tag_names([tag1, tag2, tag3]))
|
||||
end
|
||||
end
|
||||
|
||||
context 'tag synonyms' do
|
||||
fab!(:base_tag) { Fabricate(:tag, name: 'discourse') }
|
||||
fab!(:synonym) { Fabricate(:tag, name: 'discource', target_tag: base_tag) }
|
||||
|
Loading…
x
Reference in New Issue
Block a user