mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-01 13:54:35 +03:00
delete null values from incoming objects
no issue - add more power to validation phase (checkObject) to get rid of null values
This commit is contained in:
parent
dac44b4d4b
commit
7d4107fec4
@ -283,6 +283,15 @@ utils = {
|
||||
}
|
||||
}
|
||||
|
||||
// will remove unwanted null values
|
||||
_.each(object[docName], function (value, index) {
|
||||
if (!_.isObject(object[docName][index])) {
|
||||
return;
|
||||
}
|
||||
|
||||
object[docName][index] = _.omit(object[docName][index], _.isNull);
|
||||
});
|
||||
|
||||
if (editId && object[docName][0].id && parseInt(editId, 10) !== parseInt(object[docName][0].id, 10)) {
|
||||
return errors.logAndRejectError(new errors.BadRequestError(i18n.t('errors.api.utils.invalidIdProvided')));
|
||||
}
|
||||
|
@ -370,6 +370,25 @@ describe('API Utils', function () {
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('will delete null values from object', function (done) {
|
||||
var object = {test: [{id: 1, key: null}]};
|
||||
|
||||
apiUtils.checkObject(_.cloneDeep(object), 'test').then(function (data) {
|
||||
should.not.exist(data.test[0].key);
|
||||
should.exist(data.test[0].id);
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
|
||||
it('will not break if the expected object is a string', function (done) {
|
||||
var object = {test: ['something']};
|
||||
|
||||
apiUtils.checkObject(_.cloneDeep(object), 'test').then(function (data) {
|
||||
data.test[0].should.eql('something');
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkFileExists', function () {
|
||||
|
Loading…
Reference in New Issue
Block a user