A platform for community discussion. Free, open, simple.
FIX: Complete underscore support in topic tag filter regex (#37552)
Sam73e021abdaec
diff --git a/lib/topics_filter.rb b/lib/topics_filter.rbindex 6fc2517d30d..65121ad4ba9 100644--- a/lib/topics_filter.rb+++ b/lib/topics_filter.rb@@ -901,7 +901,7 @@ class TopicsFilterbreak if key_prefix && key_prefix != "-"value.scan(- /\A(?<tag_names>([\p{N}\p{L}\-_]+)(?<delimiter>[,+])?([\p{N}\p{L}\-]+)?(\k<delimiter>[\p{N}\p{L}\-]+)*)\z/,+ /\A(?<tag_names>([\p{N}\p{L}\-_]+)(?<delimiter>[,+])?([\p{N}\p{L}\-_]+)?(\k<delimiter>[\p{N}\p{L}\-_]+)*)\z/,) do |tag_names, delimiter|match_all =if delimiter == ","diff --git a/spec/lib/topics_filter_spec.rb b/spec/lib/topics_filter_spec.rbindex d9c47b27c5d..0f7fb29ba49 100644--- a/spec/lib/topics_filter_spec.rb+++ b/spec/lib/topics_filter_spec.rb@@ -1492,6 +1492,31 @@ RSpec.describe TopicsFilter do).to contain_exactly(topic_with_tag.id, topic_with_tag_and_tag2.id)endend++ describe "when query string contains multiple tags with underscores" do+ before do+ tag.update!(name: "tag_one")+ tag2.update!(name: "tag_two")+ end++ it "should return topics when filtering with comma-separated underscore tags" do+ expect(+ TopicsFilter+ .new(guardian: Guardian.new)+ .filter_from_query_string("tags:tag_one,tag_two")+ .pluck(:id),+ ).to contain_exactly(topic_with_tag.id, topic_with_tag_and_tag2.id, topic_with_tag2.id)+ end++ it "should return topics when filtering with plus-separated underscore tags" do+ expect(+ TopicsFilter+ .new(guardian: Guardian.new)+ .filter_from_query_string("tags:tag_one+tag_two")+ .pluck(:id),+ ).to contain_exactly(topic_with_tag_and_tag2.id)+ end+ endenddescribe "when filtering by tag_groups" do