Scheduling infrastructure for absolutely everyone.
Transform # character to - in slug (#10896)
Ujwal Kumar31d4cb4eb77c
diff --git a/packages/lib/slugify.test.ts b/packages/lib/slugify.test.tsindex 7a7b2a35012..0cf97603038 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.tsindex 93e76658c93..a14897e34e1 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;