mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 03:40:00 +08:00
FIX: Handle tags with underscores correctly (#26839)
This commit is contained in:
parent
3c4a15a35f
commit
9f9c7f0a23
|
@ -509,8 +509,8 @@ module DiscourseTagging
|
|||
|
||||
term = opts[:term]
|
||||
if term.present?
|
||||
term = term.gsub("_", "\\_").downcase
|
||||
builder_params[:cleaned_term] = term
|
||||
term = term.gsub("_", "\\_").downcase
|
||||
|
||||
if opts[:term_type] == DiscourseTagging.term_types[:starts_with]
|
||||
builder_params[:term] = "#{term}%"
|
||||
|
|
|
@ -426,6 +426,24 @@ RSpec.describe DiscourseTagging do
|
|||
expect(tags).to contain_exactly(tag1.name, tag3.name)
|
||||
end
|
||||
|
||||
context "with tags with underscores" do
|
||||
fab!(:tag_with_underscore) { Fabricate(:tag, name: "tag_1") }
|
||||
fab!(:another_tag_with_underscore) do
|
||||
Fabricate(:tag, name: "tag_1a", public_topic_count: 10)
|
||||
end
|
||||
|
||||
it "puts the exact match at the start of the results" do
|
||||
tags =
|
||||
DiscourseTagging.filter_allowed_tags(
|
||||
nil,
|
||||
term: "tag_1",
|
||||
order_search_results: true,
|
||||
).map(&:name)
|
||||
|
||||
expect(tags).to eq(%w[tag_1 tag_1a])
|
||||
end
|
||||
end
|
||||
|
||||
context "with tag with colon" do
|
||||
fab!(:tag_with_colon) { Fabricate(:tag, name: "with:colon") }
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user