A platform for community discussion. Free, open, simple.
DEV: Fix `category:` filter only supported alphabets and numbers (#21427)
Alan Guo Xiang Tan0c8d3f854267
diff --git a/app/models/category.rb b/app/models/category.rbindex 9d7ff8898c2..0b0363f39bd 100644--- a/app/models/category.rb+++ b/app/models/category.rb@@ -229,7 +229,9 @@ class Category < ActiveRecord::Basesqls =slugs.map do |slug|- category_slugs = slug.split(":").first(SiteSetting.max_category_nesting)+ category_slugs =+ slug.split(":").first(SiteSetting.max_category_nesting).map { Slug.for(_1, "") }+sql = ""if category_slugs.length == 1diff --git a/lib/topics_filter.rb b/lib/topics_filter.rbindex 52e27c99ffd..c12052c5a3f 100644--- a/lib/topics_filter.rb+++ b/lib/topics_filter.rb@@ -203,7 +203,7 @@ class TopicsFiltervalue.scan(- /\A(?<category_slugs>([a-zA-Z0-9\-:]+)(?<delimiter>[,])?([a-zA-Z0-9\-:]+)?(\k<delimiter>[a-zA-Z0-9\-:]+)*)\z/,+ /\A(?<category_slugs>([\p{L}\p{N}\-:]+)(?<delimiter>[,])?([\p{L}\p{N}\-:]+)?(\k<delimiter>[\p{L}\p{N}\-:]+)*)\z/,).each do |category_slugs_match, delimiter|slugs = category_slugs_match.split(delimiter)diff --git a/spec/lib/topics_filter_spec.rb b/spec/lib/topics_filter_spec.rbindex 93398876345..aa82ad25fcd 100644--- a/spec/lib/topics_filter_spec.rb+++ b/spec/lib/topics_filter_spec.rb@@ -434,6 +434,37 @@ RSpec.describe TopicsFilter doendend+ describe "when `slug_generation_method` site setting is set to encoded" do+ before do+ SiteSetting.slug_generation_method = "encoded"+ category.update!(name: "日本語", slug: "日本語")+ end++ describe "when query string is `category:日本語`" do+ it 'should return topics from category with slug "日本語"' do+ expect(+ TopicsFilter+ .new(guardian: Guardian.new)+ .filter_from_query_string("category:日本語")+ .pluck(:id),+ ).to contain_exactly(topic_in_category.id, topic_in_category_subcategory.id)+ end+ end++ describe "when query string is `category:日本語:안녕하세요`" do+ before { category_subcategory.update!(name: "안녕하세요 ", slug: "안녕하세요 ") }++ it "should return topics from category with slug '안녕하세요'" do+ expect(+ TopicsFilter+ .new(guardian: Guardian.new)+ .filter_from_query_string("category:日本語:안녕하세요")+ .pluck(:id),+ ).to contain_exactly(topic_in_category_subcategory.id)+ end+ end+ end+describe "when multiple categories have subcategories with the same name" dofab!(:category_subcategory) doFabricate(:category, parent_category: category, name: "subcategory")