FIX: Complete underscore support in topic tag filter regex (#37552)

Adds support of `tags:hello_world,hello_not_world`
This commit is contained in:
Sam
2026-02-05 17:59:53 +11:00
committed by GitHub
parent e60890dbae
commit 73e021abda
2 changed files with 26 additions and 1 deletions
+1 -1
View File
@@ -901,7 +901,7 @@ class TopicsFilter
break 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 == ","
+25
View File
@@ -1492,6 +1492,31 @@ RSpec.describe TopicsFilter do
).to contain_exactly(topic_with_tag.id, topic_with_tag_and_tag2.id)
end
end
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
end
end
describe "when filtering by tag_groups" do