A platform for community discussion. Free, open, simple.
FIX: prevents crash in discourse_tagging with empty term (#8548)
Joffrey JAFFEUX81b4de39ee77
diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rbindex 3abeefbe925..94b9f2cf93b 100644--- a/lib/discourse_tagging.rb+++ b/lib/discourse_tagging.rb@@ -222,7 +222,7 @@ module DiscourseTaggingdistinct_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 DiscourseTaggingterm = opts[:term]if term.present?- term = term.gsub("_", "\\_")- clean_tag(term)- term.downcase!+ term = term.gsub("_", "\\_").downcasebuilder.where("LOWER(name) LIKE :term")builder_params[:cleaned_term] = termbuilder_params[:term] = "%#{term}%"diff --git a/spec/components/discourse_tagging_spec.rb b/spec/components/discourse_tagging_spec.rbindex dcd0f7f1c3d..ee12b4ce37b 100644--- a/spec/components/discourse_tagging_spec.rb+++ b/spec/components/discourse_tagging_spec.rb@@ -129,6 +129,16 @@ describe DiscourseTagging doendend+ 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' dofab!(:base_tag) { Fabricate(:tag, name: 'discourse') }fab!(:synonym) { Fabricate(:tag, name: 'discource', target_tag: base_tag) }