mirror of
https://github.com/discourse/discourse.git
synced 2026-08-05 18:57:20 -05:00
FIX: Complete underscore support in topic tag filter regex (#37552)
Adds support of `tags:hello_world,hello_not_world`
This commit is contained in:
@@ -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 == ","
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user