fix: sanitize dots in path collection config (#3518)

This commit is contained in:
Erez Rokah 2020-04-01 16:40:14 +03:00 committed by GitHub
parent a8678559b2
commit 601175c6a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -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', () => {

View File

@ -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),
);