mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-28 14:03:48 +03:00
Added custom json-string
format to AJV validator
no issue - the value of `mobiledoc` when submitting a page/post via the API must be JSON, but we don't validate this - this results in url-utils throwing an error, which ends up being a 500 - this commit adds a custom format to AJV to validate it is valid JSON - also updates tests with bad JSON - 'a'
This commit is contained in:
parent
374b43ceab
commit
8853067830
@ -19,6 +19,7 @@
|
||||
},
|
||||
"mobiledoc": {
|
||||
"type": ["string", "null"],
|
||||
"format": "json-string",
|
||||
"maxLength": 1000000000
|
||||
},
|
||||
"html": {
|
||||
|
@ -19,6 +19,7 @@
|
||||
},
|
||||
"mobiledoc": {
|
||||
"type": ["string", "null"],
|
||||
"format": "json-string",
|
||||
"maxLength": 1000000000
|
||||
},
|
||||
"html": {
|
||||
|
@ -5,7 +5,17 @@ const common = require('../../../../../lib/common');
|
||||
|
||||
const ajv = new Ajv({
|
||||
allErrors: true,
|
||||
useDefaults: true
|
||||
useDefaults: true,
|
||||
formats: {
|
||||
'json-string': (data) => {
|
||||
try {
|
||||
JSON.parse(data);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
stripKeyword(ajv);
|
||||
|
@ -19,6 +19,7 @@
|
||||
},
|
||||
"mobiledoc": {
|
||||
"type": ["string", "null"],
|
||||
"format": "json-string",
|
||||
"maxLength": 1000000000
|
||||
},
|
||||
"html": {
|
||||
|
@ -19,6 +19,7 @@
|
||||
},
|
||||
"mobiledoc": {
|
||||
"type": ["string", "null"],
|
||||
"format": "json-string",
|
||||
"maxLength": 1000000000
|
||||
},
|
||||
"html": {
|
||||
|
@ -5,7 +5,17 @@ const common = require('../../../../../lib/common');
|
||||
|
||||
const ajv = new Ajv({
|
||||
allErrors: true,
|
||||
useDefaults: true
|
||||
useDefaults: true,
|
||||
formats: {
|
||||
'json-string': (data) => {
|
||||
try {
|
||||
JSON.parse(data);
|
||||
return true;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
stripKeyword(ajv);
|
||||
|
@ -140,7 +140,7 @@ describe('Unit: canary/utils/validators/input/pages', function () {
|
||||
const fieldMap = {
|
||||
title: [123, new Date(), _.repeat('a', 2001)],
|
||||
slug: [123, new Date(), _.repeat('a', 192)],
|
||||
mobiledoc: [123, new Date()],
|
||||
mobiledoc: [123, new Date(), 'a'],
|
||||
feature_image: [123, new Date(), 'random words'],
|
||||
featured: [123, new Date(), 'abc'],
|
||||
status: [123, new Date(), 'abc'],
|
||||
|
@ -140,7 +140,7 @@ describe('Unit: canary/utils/validators/input/posts', function () {
|
||||
const fieldMap = {
|
||||
title: [123, new Date(), _.repeat('a', 2001)],
|
||||
slug: [123, new Date(), _.repeat('a', 192)],
|
||||
mobiledoc: [123, new Date()],
|
||||
mobiledoc: [123, new Date(), 'a'],
|
||||
feature_image: [123, new Date(), 'random words'],
|
||||
featured: [123, new Date(), 'abc'],
|
||||
status: [123, new Date(), 'abc'],
|
||||
|
@ -140,7 +140,7 @@ describe('Unit: v2/utils/validators/input/pages', function () {
|
||||
const fieldMap = {
|
||||
title: [123, new Date(), _.repeat('a', 2001)],
|
||||
slug: [123, new Date(), _.repeat('a', 192)],
|
||||
mobiledoc: [123, new Date()],
|
||||
mobiledoc: [123, new Date(), 'a'],
|
||||
feature_image: [123, new Date(), 'random words'],
|
||||
featured: [123, new Date(), 'abc'],
|
||||
status: [123, new Date(), 'abc'],
|
||||
|
@ -140,7 +140,7 @@ describe('Unit: v2/utils/validators/input/posts', function () {
|
||||
const fieldMap = {
|
||||
title: [123, new Date(), _.repeat('a', 2001)],
|
||||
slug: [123, new Date(), _.repeat('a', 192)],
|
||||
mobiledoc: [123, new Date()],
|
||||
mobiledoc: [123, new Date(), 'a'],
|
||||
feature_image: [123, new Date(), 'random words'],
|
||||
featured: [123, new Date(), 'abc'],
|
||||
status: [123, new Date(), 'abc'],
|
||||
|
@ -140,7 +140,7 @@ describe('Unit: v3/utils/validators/input/pages', function () {
|
||||
const fieldMap = {
|
||||
title: [123, new Date(), _.repeat('a', 2001)],
|
||||
slug: [123, new Date(), _.repeat('a', 192)],
|
||||
mobiledoc: [123, new Date()],
|
||||
mobiledoc: [123, new Date(), 'a'],
|
||||
feature_image: [123, new Date(), 'random words'],
|
||||
featured: [123, new Date(), 'abc'],
|
||||
status: [123, new Date(), 'abc'],
|
||||
|
@ -140,7 +140,7 @@ describe('Unit: v3/utils/validators/input/posts', function () {
|
||||
const fieldMap = {
|
||||
title: [123, new Date(), _.repeat('a', 2001)],
|
||||
slug: [123, new Date(), _.repeat('a', 192)],
|
||||
mobiledoc: [123, new Date()],
|
||||
mobiledoc: [123, new Date(), 'a'],
|
||||
feature_image: [123, new Date(), 'random words'],
|
||||
featured: [123, new Date(), 'abc'],
|
||||
status: [123, new Date(), 'abc'],
|
||||
|
Loading…
Reference in New Issue
Block a user