FIX: Handle encoded slugs for subcategories

This commit is contained in:
Rafael dos Santos Silva 2019-10-17 17:02:17 -03:00
parent 85140aa09a
commit f97b6e85da
2 changed files with 9 additions and 2 deletions

View File

@ -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)
)
);
});
}

View File

@ -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