From 52e54fdb99d561bdc903e6d057e0947e4b1734a0 Mon Sep 17 00:00:00 2001 From: Erez Rokah Date: Wed, 1 Apr 2020 16:40:14 +0300 Subject: [PATCH] fix: sanitize dots in path collection config (#3518) --- .../src/lib/__tests__/formatters.spec.js | 15 +++++++++++++++ packages/netlify-cms-core/src/lib/formatters.ts | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/netlify-cms-core/src/lib/__tests__/formatters.spec.js b/packages/netlify-cms-core/src/lib/__tests__/formatters.spec.js index 42a546445b74..303564aed305 100644 --- a/packages/netlify-cms-core/src/lib/__tests__/formatters.spec.js +++ b/packages/netlify-cms-core/src/lib/__tests__/formatters.spec.js @@ -281,6 +281,21 @@ describe('formatters', () => { ), ).toBe('sub_dir/2020/2020-01-01-post-title.en'); }); + + it(`should replace '.' in path with -`, () => { + selectIdentifier.mockReturnValueOnce('title'); + + expect( + slugFormatter( + Map({ + slug: '{{slug}}.en', + path: '../dir/{{slug}}', + }), + Map({ title: 'Post Title' }), + slugConfig, + ), + ).toBe('--/dir/post-title.en'); + }); }); describe('previewUrlFormatter', () => { diff --git a/packages/netlify-cms-core/src/lib/formatters.ts b/packages/netlify-cms-core/src/lib/formatters.ts index a4b320bd2916..04012f05d8bd 100644 --- a/packages/netlify-cms-core/src/lib/formatters.ts +++ b/packages/netlify-cms-core/src/lib/formatters.ts @@ -115,7 +115,7 @@ export const slugFormatter = ( if (!collection.has('path')) { return slug; } else { - const pathTemplate = collection.get('path') as string; + const pathTemplate = prepareSlug(collection.get('path') as string); return compileStringTemplate(pathTemplate, date, slug, entryData, (value: string) => value === slug ? value : processSegment(value), );