fix(config): allow empty public folder for collection,file,field (#5391)

This commit is contained in:
Erez Rokah 2021-05-16 05:31:15 -07:00 committed by GitHub
parent f0725a8379
commit 558b21f700
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 4 deletions

View File

@ -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: [

View File

@ -69,7 +69,7 @@ function getConfigUrl() {
}
function setDefaultPublicFolderForField<T extends CmsField>(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;
}