FIX: experimental topics filter should allow tags with underscore (#27994)

When tags contain an underscore we should allow filtering in the same way, previously due to the regex those with underscores were not being found when filtering.
This commit is contained in:
David Battersby 2024-07-20 00:58:29 +04:00 committed by GitHub
parent 8b18fd1556
commit 43aa47b118
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 1 deletions

View File

@ -408,7 +408,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 == ","

View File

@ -964,6 +964,18 @@ RSpec.describe TopicsFilter do
).to contain_exactly(topic_with_tag.id, topic_with_tag_and_tag2.id)
end
end
describe "when query string is `tags:tag_name`" do
before { tag.update!(name: "tag_with_underscore") }
it "should return topics even when tag contains underscore" do
expect(
TopicsFilter
.new(guardian: Guardian.new)
.filter_from_query_string("tags:#{tag.name}")
.pluck(:id),
).to contain_exactly(topic_with_tag.id, topic_with_tag_and_tag2.id)
end
end
end
describe "when filtering by tag_groups" do