diff --git a/packages/lib/slugify.test.ts b/packages/lib/slugify.test.ts index 7a7b2a3501..0cf9760303 100644 --- a/packages/lib/slugify.test.ts +++ b/packages/lib/slugify.test.ts @@ -8,10 +8,12 @@ describe("slugify", () => { expect(slugify("HELLO")).toEqual("hello"); }); - it("should convert spaces, _, and any other special character to -", () => { + it("should convert spaces, _, +, # and any other special character to -", () => { expect(slugify("hello there")).toEqual("hello-there"); expect(slugify("hello_there")).toEqual("hello-there"); expect(slugify("hello$there")).toEqual("hello-there"); + expect(slugify("hello+there")).toEqual("hello-there"); + expect(slugify("#hellothere")).toEqual("hellothere"); }); it("should keep numbers as is", () => { diff --git a/packages/lib/slugify.ts b/packages/lib/slugify.ts index 93e76658c9..a14897e34e 100644 --- a/packages/lib/slugify.ts +++ b/packages/lib/slugify.ts @@ -5,10 +5,9 @@ export const slugify = (str: string) => { .normalize("NFD") // Normalize to decomposed form for handling accents .replace(/\p{Diacritic}/gu, "") // Remove any diacritics (accents) from characters .replace(/[^\p{L}\p{N}\p{Zs}\p{Emoji}]+/gu, "-") // Replace any non-alphanumeric characters (including Unicode) with a dash - .replace(/[\s_]+/g, "-") // Replace whitespace and underscores with a single dash + .replace(/[\s_#]+/g, "-") // Replace whitespace, # and underscores with a single dash .replace(/^-+/, "") // Remove dashes from start - .replace(/-+$/, "") // Remove dashes from end - .replace(/\+/g, "-"); // Transform all + to - + .replace(/-+$/, ""); // Remove dashes from end }; export default slugify;