FIX: category routes model params should decode their URL parts (#8612)

* FIX: category routes model params should decode their URL parts

Ember's route star globbing does not uri decode by default. This is
problematic for subcategory globs with encoded URL site settings enabled.

Subcategories with encoded URLs will 404 without this decode.

I found this https://github.com/tildeio/route-recognizer/pull/91
which explicitly explains that globbing does not decode automatically.
This commit is contained in:
Jeff Wong 2019-12-23 10:24:41 -08:00 committed by GitHub
parent e36efb1edc
commit 63323bd7a8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -334,7 +334,11 @@ Category.reopenClass({
}, },
findBySlugPathWithID(slugPathWithID) { findBySlugPathWithID(slugPathWithID) {
const parts = slugPathWithID.split("/"); let parts = slugPathWithID.split("/");
// slugs found by star/glob pathing in emeber do not automatically url decode - ensure that these are decoded
if (Discourse.SiteSettings.slug_generation_method === "encoded") {
parts = parts.map(urlPart => decodeURI(urlPart));
}
let category = null; let category = null;
if (parts.length > 0 && parts[parts.length - 1].match(/^\d+$/)) { if (parts.length > 0 && parts[parts.length - 1].match(/^\d+$/)) {