mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-04-08 02:52:39 -05:00
Allowed for repeated query parameters for arrays (#10021)
no-issue There are a few libraries, including node core that when given an array for a query parameter will encode it as repeated query params. e.g. ``` {someParam: ['a', 'b']} // becomes '?someParam=a&someParam=b' ``` This adds a check for the value to stop us 500ing on repeated keys and to add easier interop with http clients
This commit is contained in:
parent
2c603c8a8a
commit
4f1866a263
2 changed files with 29 additions and 1 deletions
|
@ -54,7 +54,7 @@ const validate = (config, attrs) => {
|
|||
return;
|
||||
}
|
||||
|
||||
const valuesAsArray = value.trim().toLowerCase().split(',');
|
||||
const valuesAsArray = Array.isArray(value) ? value : value.trim().toLowerCase().split(',');
|
||||
const unallowedValues = _.filter(valuesAsArray, (value) => {
|
||||
return !allowedValues.includes(value);
|
||||
});
|
||||
|
|
|
@ -79,6 +79,34 @@ describe('Unit: api/shared/validators/input/all', function () {
|
|||
return shared.validators.input.all.all(apiConfig, frame);
|
||||
});
|
||||
|
||||
it('supports include being an array', function () {
|
||||
const frame = {
|
||||
options: {
|
||||
context: {},
|
||||
slug: 'slug',
|
||||
include: ['tags', 'authors'],
|
||||
page: 2
|
||||
}
|
||||
};
|
||||
|
||||
const apiConfig = {
|
||||
options: {
|
||||
include: {
|
||||
values: ['tags', 'authors'],
|
||||
required: true
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
return shared.validators.input.all.all(apiConfig, frame)
|
||||
.then(() => {
|
||||
should.exist(frame.options.page);
|
||||
should.exist(frame.options.slug);
|
||||
should.exist(frame.options.include);
|
||||
should.exist(frame.options.context);
|
||||
});
|
||||
});
|
||||
|
||||
it('default include array notation', function () {
|
||||
const frame = {
|
||||
options: {
|
||||
|
|
Loading…
Add table
Reference in a new issue