mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-11-30 21:40:39 +03:00
Merge pull request #2737 from jaswilli/issue-2736-pg
Ensure settings values are strings before saving
This commit is contained in:
commit
169a984372
@ -214,6 +214,10 @@ settings = {
|
||||
return when.all(checks);
|
||||
};
|
||||
|
||||
if (!_.isString(value)) {
|
||||
value = JSON.stringify(value);
|
||||
}
|
||||
|
||||
// Allow shorthand syntax
|
||||
if (_.isString(key)) {
|
||||
key = { settings: [{ key: key, value: value }]};
|
||||
@ -247,4 +251,4 @@ settings = {
|
||||
};
|
||||
|
||||
module.exports = settings;
|
||||
module.exports.updateSettingsCache = updateSettingsCache;
|
||||
module.exports.updateSettingsCache = updateSettingsCache;
|
||||
|
@ -163,4 +163,16 @@ describe('Settings API', function () {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('ensures values are stringified before saving to database', function (done) {
|
||||
return callApiWithContext(defaultContext, 'edit', 'title', []).then(function (response) {
|
||||
should.exist(response);
|
||||
testUtils.API.checkResponse(response, 'settings');
|
||||
response.settings.length.should.equal(1);
|
||||
testUtils.API.checkResponse(response.settings[0], 'setting');
|
||||
response.settings[0].value.should.equal('[]');
|
||||
|
||||
done();
|
||||
}).catch(done);
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user