FIX: Make 'findBySlugPathWithID' when URL ends with a slash (#8699)
Make URLs such as 'https://discourse/c/foo/bar/' work the same way 'https://discourse/c/foo/bar' does.
This commit is contained in:
parent
6e480392ea
commit
815116f6a2
|
@ -334,7 +334,7 @@ Category.reopenClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
findBySlugPathWithID(slugPathWithID) {
|
findBySlugPathWithID(slugPathWithID) {
|
||||||
let parts = slugPathWithID.split("/");
|
let parts = slugPathWithID.split("/").filter(Boolean);
|
||||||
// slugs found by star/glob pathing in emeber do not automatically url decode - ensure that these are decoded
|
// 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") {
|
if (Discourse.SiteSettings.slug_generation_method === "encoded") {
|
||||||
parts = parts.map(urlPart => decodeURI(urlPart));
|
parts = parts.map(urlPart => decodeURI(urlPart));
|
||||||
|
|
|
@ -184,6 +184,30 @@ QUnit.test("findSingleBySlug", assert => {
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QUnit.test("findBySlugPathWithID", assert => {
|
||||||
|
const store = createStore();
|
||||||
|
|
||||||
|
const foo = store.createRecord("category", { id: 1, slug: "foo" });
|
||||||
|
const bar = store.createRecord("category", {
|
||||||
|
id: 2,
|
||||||
|
slug: "bar",
|
||||||
|
parentCategory: foo
|
||||||
|
});
|
||||||
|
const baz = store.createRecord("category", {
|
||||||
|
id: 3,
|
||||||
|
slug: "baz",
|
||||||
|
parentCategory: foo
|
||||||
|
});
|
||||||
|
|
||||||
|
const categoryList = [foo, bar, baz];
|
||||||
|
sandbox.stub(Category, "list").returns(categoryList);
|
||||||
|
|
||||||
|
assert.deepEqual(Category.findBySlugPathWithID("foo"), foo);
|
||||||
|
assert.deepEqual(Category.findBySlugPathWithID("foo/bar"), bar);
|
||||||
|
assert.deepEqual(Category.findBySlugPathWithID("foo/bar/"), bar);
|
||||||
|
assert.deepEqual(Category.findBySlugPathWithID("foo/baz/3"), baz);
|
||||||
|
});
|
||||||
|
|
||||||
QUnit.test("search with category name", assert => {
|
QUnit.test("search with category name", assert => {
|
||||||
const store = createStore(),
|
const store = createStore(),
|
||||||
category1 = store.createRecord("category", {
|
category1 = store.createRecord("category", {
|
||||||
|
|
Loading…
Reference in New Issue