mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-27 22:49:56 -05:00
Merge pull request #2737 from jaswilli/issue-2736-pg
Ensure settings values are strings before saving
This commit is contained in:
commit
169a984372
2 changed files with 18 additions and 2 deletions
|
@ -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…
Add table
Reference in a new issue