FIX: support non-english tags in tag input field

This commit is contained in:
Neil Lalonde 2017-07-07 14:48:08 -04:00
parent 6f09df0deb
commit a509146ea5
2 changed files with 16 additions and 2 deletions

View File

@ -64,9 +64,8 @@ module DiscourseTagging
def self.filter_allowed_tags(query, guardian, opts={})
term = opts[:term]
if term.present?
term.downcase!
term.gsub!(/[^a-z0-9\.\-\_]*/, '')
term.gsub!("_", "\\_")
term = clean_tag(term)
query = query.where('tags.name like ?', "%#{term}%")
end

View File

@ -130,6 +130,21 @@ describe TagsController do
json = ::JSON.parse(response.body)
expect(json["results"].map{|j| j["id"]}).to eq(['cooltag'])
end
it "supports Chinese and Russian" do
tag_names = ['房地产', 'тема-в-разработке']
tag_names.each { |name| Fabricate(:tag, name: name) }
xhr :get, :search, q: '房'
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["results"].map{|j| j["id"]}).to eq(['房地产'])
xhr :get, :search, q: 'тема'
expect(response).to be_success
json = ::JSON.parse(response.body)
expect(json["results"].map{|j| j["id"]}).to eq(['тема-в-разработке'])
end
end
end
end