FIX: ensure that we encode a slug only once if slug generation method is encoded

This was re-encoding the search slug each loop - if the category list was not
the first category in the list, it'd continually search with a re-encoded search
term from the previous iteration. This results in ember 404ing when navigating
to raw encoded category slugs of the form /c/encoded-slug-with-non-ascii
that have no ID attached.
This commit is contained in:
Jeff Wong 2019-12-22 00:25:12 -08:00
parent eca1c643d5
commit e36efb1edc
1 changed files with 3 additions and 4 deletions

View File

@ -308,11 +308,10 @@ Category.reopenClass({
},
findBySlugAndParent(slug, parentCategory) {
if (Discourse.SiteSettings.slug_generation_method === "encoded") {
slug = encodeURI(slug);
}
return Category.list().find(category => {
if (Discourse.SiteSettings.slug_generation_method === "encoded") {
slug = encodeURI(slug);
}
return (
category.slug === slug &&
(category.parentCategory || null) === parentCategory