mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 11:23:25 +08:00
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) {
|
||||
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
|
||||
if (Discourse.SiteSettings.slug_generation_method === "encoded") {
|
||||
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 => {
|
||||
const store = createStore(),
|
||||
category1 = store.createRecord("category", {
|
||||
|
|
Loading…
Reference in New Issue
Block a user