diff --git a/lib/discourse_tagging.rb b/lib/discourse_tagging.rb index fa70a4407af..a964a8a22a0 100644 --- a/lib/discourse_tagging.rb +++ b/lib/discourse_tagging.rb @@ -724,8 +724,8 @@ module DiscourseTagging tag.strip! tag.gsub!(/[[:space:]]+/, "-") tag.gsub!(/[^[:word:][:punct:]]+/, "") - tag.squeeze!("-") tag.gsub!(TAGS_FILTER_REGEXP, "") + tag.squeeze!("-") tag[0...SiteSetting.max_tag_length] end diff --git a/spec/lib/discourse_tagging_spec.rb b/spec/lib/discourse_tagging_spec.rb index 996e0ee423a..42b0a8ee348 100644 --- a/spec/lib/discourse_tagging_spec.rb +++ b/spec/lib/discourse_tagging_spec.rb @@ -1479,6 +1479,11 @@ RSpec.describe DiscourseTagging do it "removes zero-width spaces" do expect(DiscourseTagging.clean_tag("hel\ufefflo")).to eq("hello") end + + it "removes multiple consecutive dashes" do + expect(DiscourseTagging.clean_tag("hello---world")).to eq("hello-world") + expect(DiscourseTagging.clean_tag("Finances & Accounting")).to eq("finances-accounting") + end end end