diff --git a/ghost/collections/src/Collection.ts b/ghost/collections/src/Collection.ts index cc31f1e4ce..39d2dc6029 100644 --- a/ghost/collections/src/Collection.ts +++ b/ghost/collections/src/Collection.ts @@ -69,7 +69,7 @@ export class Collection { } public async edit(data: Partial, uniqueChecker: UniqueChecker) { - if (this.type === 'automatic' && (data.filter === null || data.filter === '')) { + if (this.type === 'automatic' && this.slug !== 'index' && (data.filter === null || data.filter === '')) { throw new ValidationError({ message: tpl(messages.invalidFilterProvided.message), context: tpl(messages.invalidFilterProvided.context) @@ -201,7 +201,7 @@ export class Collection { }); } - if (data.type === 'automatic' && !data.filter) { + if (data.type === 'automatic' && (data.slug !== 'index') && !data.filter) { // @NOTE: add filter validation here throw new ValidationError({ message: tpl(messages.invalidFilterProvided.message), diff --git a/ghost/collections/test/Collection.test.ts b/ghost/collections/test/Collection.test.ts index 4d2bc5f7c0..f4a2ac42e6 100644 --- a/ghost/collections/test/Collection.test.ts +++ b/ghost/collections/test/Collection.test.ts @@ -209,6 +209,23 @@ describe('Collection', function () { return true; }); }); + + it('Does not throw when collection filter is empty for automatic "index" collection', async function (){ + const collection = await Collection.create({ + title: 'Index', + slug: 'index', + type: 'automatic', + filter: '' + }); + + const editedCollection = await collection.edit({ + title: 'Edited index', + filter: '' + }, uniqueChecker); + + assert.equal(editedCollection.title, 'Edited index'); + assert.equal(editedCollection.filter, ''); + }); }); it('Can add posts to different positions', async function () {