From 020eba46230c63795ae26890c7cb96d45548eab4 Mon Sep 17 00:00:00 2001 From: Maja Komel Date: Mon, 27 Aug 2018 03:05:28 +0200 Subject: [PATCH] FIX: find tags with non-latin names (#6312) --- lib/search.rb | 6 +++--- spec/components/search_spec.rb | 11 ++++++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/lib/search.rb b/lib/search.rb index 3cabcd0837b..a90f651518a 100644 --- a/lib/search.rb +++ b/lib/search.rb @@ -372,7 +372,7 @@ class Search end end - advanced_filter(/^\#([a-zA-Z0-9\-:=]+)/) do |posts, match| + advanced_filter(/^\#([\p{L}0-9\-:=]+)/) do |posts, match| exact = true @@ -468,11 +468,11 @@ class Search end end - advanced_filter(/^tags?:([a-zA-Z0-9,\-_+]+)/) do |posts, match| + advanced_filter(/^tags?:([\p{L}0-9,\-_+]+)/) do |posts, match| search_tags(posts, match, positive: true) end - advanced_filter(/\-tags?:([a-zA-Z0-9,\-_+]+)/) do |posts, match| + advanced_filter(/\-tags?:([\p{L}0-9,\-_+]+)/) do |posts, match| search_tags(posts, match, positive: false) end diff --git a/spec/components/search_spec.rb b/spec/components/search_spec.rb index 163921da276..c5e98e9a5d2 100644 --- a/spec/components/search_spec.rb +++ b/spec/components/search_spec.rb @@ -822,8 +822,9 @@ describe Search do expect(Search.execute("sams post #sub-category").posts.length).to eq(1) # tags - topic.tags = [Fabricate(:tag, name: 'alpha')] + topic.tags = [Fabricate(:tag, name: 'alpha'), Fabricate(:tag, name: 'привет')] expect(Search.execute('this is a test #alpha').posts.map(&:id)).to eq([post.id]) + expect(Search.execute('this is a test #привет').posts.map(&:id)).to eq([post.id]) expect(Search.execute('this is a test #beta').posts.size).to eq(0) end @@ -864,6 +865,14 @@ describe Search do expect(Search.execute('tags:plants').posts.size).to eq(0) end + it 'can find posts with non-latin tag' do + topic = Fabricate(:topic) + topic.tags = [Fabricate(:tag, name: 'さようなら')] + post = Fabricate(:post, raw: 'Testing post', topic: topic) + + expect(Search.execute('tags:さようなら').posts.map(&:id)).to eq([post.id]) + end + it 'can find posts with any tag from multiple tags' do Fabricate(:post)