diff --git a/packages/netlify-cms-core/src/actions/__tests__/config.spec.js b/packages/netlify-cms-core/src/actions/__tests__/config.spec.js index 91ec0334..e1d42e3c 100644 --- a/packages/netlify-cms-core/src/actions/__tests__/config.spec.js +++ b/packages/netlify-cms-core/src/actions/__tests__/config.spec.js @@ -214,7 +214,7 @@ describe('config', () => { ).toEqual('static/images/docs'); }); - it('should not overwrite collection public_folder if set', () => { + it('should not overwrite collection public_folder if set to non empty string', () => { expect( applyDefaults({ collections: [ @@ -229,6 +229,21 @@ describe('config', () => { ).toEqual('images/docs'); }); + it('should not overwrite collection public_folder if set to empty string', () => { + expect( + applyDefaults({ + collections: [ + { + folder: 'foo', + media_folder: 'static/images/docs', + public_folder: '', + fields: [{ name: 'title', widget: 'string' }], + }, + ], + }).collections[0].public_folder, + ).toEqual(''); + }); + it("should set collection media_folder and public_folder to an empty string when collection path exists, but collection media_folder doesn't", () => { const result = applyDefaults({ collections: [ diff --git a/packages/netlify-cms-core/src/actions/config.ts b/packages/netlify-cms-core/src/actions/config.ts index e8018d4b..985edd86 100644 --- a/packages/netlify-cms-core/src/actions/config.ts +++ b/packages/netlify-cms-core/src/actions/config.ts @@ -69,7 +69,7 @@ function getConfigUrl() { } function setDefaultPublicFolderForField(field: T) { - if ('media_folder' in field && !field.public_folder) { + if ('media_folder' in field && !('public_folder' in field)) { return { ...field, public_folder: field.media_folder }; } return field; @@ -271,7 +271,7 @@ export function applyDefaults(originalConfig: CmsConfig) { collection.media_folder = ''; } - if ('media_folder' in collection && !collection.public_folder) { + if ('media_folder' in collection && !('public_folder' in collection)) { collection.public_folder = collection.media_folder; } @@ -303,7 +303,7 @@ export function applyDefaults(originalConfig: CmsConfig) { for (const file of files) { file.file = trimStart(file.file, '/'); - if ('media_folder' in file && !file.public_folder) { + if ('media_folder' in file && !('public_folder' in file)) { file.public_folder = file.media_folder; }