Scheduling infrastructure for absolutely everyone.
fix: slugify from creating double+ dashes (#14002)
sean-brydon0784df6a31a2
diff --git a/packages/lib/slugify.test.ts b/packages/lib/slugify.test.tsindex 634e147c84e..042ff7a0c53 100644--- a/packages/lib/slugify.test.ts+++ b/packages/lib/slugify.test.ts@@ -45,9 +45,18 @@ describe("slugify", () => {expect(slugify("hellothere.")).toEqual("hellothere");});+ it("Should replace consecutive dashes with a single dash", () => {+ expect(slugify("Hello - World 123_ !@# Test 456 789")).toEqual("hello-world-123-test-456-789");+ });+// This is failing, if we want to fix it, one approach is as used in getValidRhfFieldName- it.skip("should remove unicode and emoji characters", () => {- expect(slugify("Hello 📚🕯️®️ There")).toEqual("hello---------there");- expect(slugify("📚🕯️®️")).toEqual("");+ it("should remove emoji characters", () => {+ expect(slugify("Hello 📚🕯️ There")).toEqual("hello-there");+ expect(slugify("📚🕯️")).toEqual("");+ });++ it.skip("should remove unicode", () => {+ expect(slugify("Hello ®️ There")).toEqual("hello-there");+ expect(slugify("®️")).toEqual("");});});diff --git a/packages/lib/slugify.ts b/packages/lib/slugify.tsindex 63d10836817..0d6a742c043 100644--- a/packages/lib/slugify.ts+++ b/packages/lib/slugify.ts@@ -5,6 +5,7 @@ export const slugify = (str: string, forDisplayingInput?: boolean) => {if (!str) {return "";}+const s = str.toLowerCase() // Convert to lowercase.trim() // Remove whitespace from both sides@@ -14,7 +15,13 @@ export const slugify = (str: string, forDisplayingInput?: boolean) => {.replace(/[\s_#]+/g, "-") // Replace whitespace, # and underscores with a single dash.replace(/^-+/, "") // Remove dashes from start.replace(/\.{2,}/g, ".") // Replace consecutive periods with a single period- .replace(/^\.+/, ""); // Remove periods from the start+ .replace(/^\.+/, "") // Remove periods from the start+ .replace(+ /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g,+ ""+ ) // Removes emojis+ .replace(/\s+/g, " ")+ .replace(/-+/g, "-"); // Replace consecutive dashes with a single dashreturn forDisplayingInput ? s : s.replace(/-+$/, "").replace(/\.*$/, ""); // Remove dashes and period from end};