FIX: Handle encoded slugs for subcategories

FIX: Handle encoded slugs for subcategories

diff --git a/app/assets/javascripts/discourse/models/category.js.es6 b/app/assets/javascripts/discourse/models/category.js.es6
index 11bdbf9b8a..665961e03d 100644
--- a/app/assets/javascripts/discourse/models/category.js.es6
+++ b/app/assets/javascripts/discourse/models/category.js.es6
@@ -283,7 +283,13 @@ Category.reopenClass({
           return (
             item &&
             item.get("parentCategory") === parentCategory &&
-            Category.slugFor(item) === parentSlug + "/" + slug
+            (
+              Discourse.SiteSettings.slug_generation_method !== "encoded" &&
+              Category.slugFor(item) === parentSlug + "/" + slug
+              ||
+              Discourse.SiteSettings.slug_generation_method === "encoded" &&
+              Category.slugFor(item) === encodeURI(parentSlug) + "/" + encodeURI(slug)
+            )
           );
         });
       }
diff --git a/app/models/category.rb b/app/models/category.rb
index e76089baad..d3273ea63d 100644
--- a/app/models/category.rb
+++ b/app/models/category.rb
@@ -607,7 +607,8 @@ class Category < ActiveRecord::Base
   end
 
   def self.query_parent_category(parent_slug)
-    self.where(slug: parent_slug, parent_category_id: nil).pluck(:id).first ||
+    encoded_parent_slug = CGI.escape(parent_slug) if SiteSetting.slug_generation_method == 'encoded'
+    self.where(slug: (encoded_parent_slug || parent_slug), parent_category_id: nil).pluck(:id).first ||
     self.where(id: parent_slug.to_i).pluck(:id).first
   end

GitHub sha: f97b6e85

1 Like

This commit has been mentioned on Discourse Meta. There might be relevant details there: