diff --git a/server/models/Collection.test.ts b/server/models/Collection.test.ts index 03999f7ef..8318bd3c9 100644 --- a/server/models/Collection.test.ts +++ b/server/models/Collection.test.ts @@ -372,6 +372,13 @@ describe("#findByPk", () => { expect(response!.id).toBe(collection.id); }); + test("should return collection when urlId is present, but missing slug", async () => { + const collection = await buildCollection(); + const id = collection.urlId; + const response = await Collection.findByPk(id); + expect(response!.id).toBe(collection.id); + }); + test("should return undefined when incorrect uuid type", async () => { const collection = await buildCollection(); const response = await Collection.findByPk(collection.id + "-incorrect"); diff --git a/server/models/Document.test.ts b/server/models/Document.test.ts index f06a37f27..f894844de 100644 --- a/server/models/Document.test.ts +++ b/server/models/Document.test.ts @@ -532,6 +532,13 @@ describe("#findByPk", () => { const response = await Document.findByPk(id); expect(response?.id).toBe(document.id); }); + + test("should return document when urlId is given without the slug prefix", async () => { + const { document } = await seed(); + const id = document.urlId; + const response = await Document.findByPk(id); + expect(response?.id).toBe(document.id); + }); }); describe("tasks", () => { diff --git a/shared/utils/urlHelpers.ts b/shared/utils/urlHelpers.ts index 1749c4f29..e665d0052 100644 --- a/shared/utils/urlHelpers.ts +++ b/shared/utils/urlHelpers.ts @@ -51,4 +51,4 @@ export function signin(service = "slack"): string { return `${process.env.URL}/auth/${service}`; } -export const SLUG_URL_REGEX = /^[0-9a-zA-Z-_~]*-([a-zA-Z0-9]{10,15})$/; +export const SLUG_URL_REGEX = /^(?:[0-9a-zA-Z-_~]*-)?([a-zA-Z0-9]{10,15})$/;