Skip to content

Commit

Permalink
fix: filter leading or tailing slashed in cms slugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Aerilym committed Oct 8, 2024
1 parent bc9a82b commit 352f5fd
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/sanity-cms/schemas/fields/basic/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,14 @@ export async function resolveAmbiguousLink(
});

if (content) {
const slug = content.slug?.current;
let slug = content.slug?.current;
// CMS slugs should never start or end with a slash
if (slug?.startsWith('/')) {
slug = slug.slice(1);
} else if (slug?.endsWith('/')) {
slug = slug.slice(0, -1);
}

if (content._type === 'post') {
let baseUrl = postBaseUrl?.startsWith('/') ? postBaseUrl : `/${postBaseUrl}`;
if (!baseUrl.endsWith('/')) {
Expand Down

0 comments on commit 352f5fd

Please sign in to comment.