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:
Dan Ungureanu 2020-01-10 17:02:36 +02:00 committed by GitHub
parent 6e480392ea
commit 815116f6a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View File

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

View File

@ -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", {