0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

🐛Fixed blog not responding when uploading routes.yaml with unknown taxonomy (#9926)

closes #9870

Instead of 500'ing when uploading a routes.yaml with an invalid taxonomy
we will now send back an error saying it's invalid.
This commit is contained in:
Fabien O'Carroll 2018-10-02 01:40:29 +07:00 committed by Katharina Irrgang
parent a15a45fa9b
commit 6cd1dc8005
2 changed files with 28 additions and 3 deletions

View file

@ -302,6 +302,7 @@ _private.validateCollections = function validateCollections(collections) {
};
_private.validateTaxonomies = function validateTaxonomies(taxonomies) {
const validRoutingTypeObjectKeys = Object.keys(RESOURCE_CONFIG.TAXONOMIES);
_.each(taxonomies, (routingTypeObject, routingTypeObjectKey) => {
if (!routingTypeObject) {
throw new common.errors.ValidationError({
@ -313,6 +314,15 @@ _private.validateTaxonomies = function validateTaxonomies(taxonomies) {
});
}
if (!validRoutingTypeObjectKeys.includes(routingTypeObjectKey)) {
throw new common.errors.ValidationError({
message: common.i18n.t('errors.services.settings.yaml.validate', {
at: routingTypeObjectKey,
reason: 'Unknown taxonomy.'
})
});
}
// CASE: we hard-require trailing slashes for the taxonomie permalink route
if (!routingTypeObject.match(/\/$/)) {
throw new common.errors.ValidationError({

View file

@ -35,7 +35,22 @@ describe('UNIT: services/settings/validate', function () {
try {
validate({
taxonomies: {
tags: '/categories/:slug/'
tag: '/categories/:slug/'
}
});
} catch (err) {
(err instanceof common.errors.ValidationError).should.be.true();
return;
}
throw new Error('should fail');
});
it('throws error when using an undefined taxonomy', function () {
try {
validate({
taxonomies: {
sweet_baked_good: '/patisserie/{slug}'
}
});
} catch (err) {
@ -220,7 +235,7 @@ describe('UNIT: services/settings/validate', function () {
}
},
taxonomies: {
tags: '/tags/{slug}/',
tag: '/tags/{slug}/',
author: '/authors/{slug}/',
}
});
@ -228,7 +243,7 @@ describe('UNIT: services/settings/validate', function () {
object.should.eql({
routes: {},
taxonomies: {
tags: '/tags/:slug/',
tag: '/tags/:slug/',
author: '/authors/:slug/'
},
collections: {