diff --git a/examples/draft-preview/src/collections/Pages/hooks/formatSlug.ts b/examples/draft-preview/src/collections/Pages/hooks/formatSlug.ts index 9d4c53dc8bc..c1c300cd3bb 100644 --- a/examples/draft-preview/src/collections/Pages/hooks/formatSlug.ts +++ b/examples/draft-preview/src/collections/Pages/hooks/formatSlug.ts @@ -2,6 +2,7 @@ import type { FieldHook } from 'payload' const format = (val: string): string => val + .trim() .replace(/ /g, '-') .replace(/[^\w-]+/g, '') .toLowerCase() diff --git a/examples/form-builder/src/utilities/formatSlug.ts b/examples/form-builder/src/utilities/formatSlug.ts index b06271b018a..58a391f48f2 100644 --- a/examples/form-builder/src/utilities/formatSlug.ts +++ b/examples/form-builder/src/utilities/formatSlug.ts @@ -2,6 +2,7 @@ import type { FieldHook } from 'payload' const format = (val: string): string => val + .trim() .replace(/ /g, '-') .replace(/[^\w-]+/g, '') .toLowerCase() diff --git a/examples/live-preview/src/collections/Pages/hooks/formatSlug.ts b/examples/live-preview/src/collections/Pages/hooks/formatSlug.ts index 9d4c53dc8bc..c1c300cd3bb 100644 --- a/examples/live-preview/src/collections/Pages/hooks/formatSlug.ts +++ b/examples/live-preview/src/collections/Pages/hooks/formatSlug.ts @@ -2,6 +2,7 @@ import type { FieldHook } from 'payload' const format = (val: string): string => val + .trim() .replace(/ /g, '-') .replace(/[^\w-]+/g, '') .toLowerCase() diff --git a/examples/localization/src/fields/slug/formatSlug.ts b/examples/localization/src/fields/slug/formatSlug.ts index e9a8fb61716..cf2cf128ff5 100644 --- a/examples/localization/src/fields/slug/formatSlug.ts +++ b/examples/localization/src/fields/slug/formatSlug.ts @@ -2,6 +2,7 @@ import type { FieldHook } from 'payload' export const formatSlug = (val: string): string => val + .trim() .replace(/ /g, '-') .replace(/[^\w-]+/g, '') .toLowerCase() diff --git a/examples/localization/src/hooks/formatSlug.ts b/examples/localization/src/hooks/formatSlug.ts index 43190f88cc2..177050045a2 100644 --- a/examples/localization/src/hooks/formatSlug.ts +++ b/examples/localization/src/hooks/formatSlug.ts @@ -2,6 +2,7 @@ import type { FieldHook } from 'payload' const format = (val: string): string => val + .trim() .replace(/ /g, '-') .replace(/[^\w-]+/g, '') .toLowerCase() diff --git a/packages/payload/src/utilities/slugify.ts b/packages/payload/src/utilities/slugify.ts index 4c190f2a049..539e7ff134d 100644 --- a/packages/payload/src/utilities/slugify.ts +++ b/packages/payload/src/utilities/slugify.ts @@ -1,5 +1,6 @@ export const slugify = (val?: string): string | undefined => val - ?.replace(/ /g, '-') + ?.trim() + .replace(/ /g, '-') .replace(/[^\w-]+/g, '') .toLowerCase() diff --git a/test/live-preview/utilities/formatSlug.ts b/test/live-preview/utilities/formatSlug.ts index 95872dd955f..ddace6272bb 100644 --- a/test/live-preview/utilities/formatSlug.ts +++ b/test/live-preview/utilities/formatSlug.ts @@ -2,6 +2,7 @@ import type { FieldHook } from 'payload' const format = (val: string): string => val + .trim() .replace(/ /g, '-') .replace(/[^\w-]+/g, '') .toLowerCase()