From 414890f263c8a8f51eb203ea9bc3bddd173ddc48 Mon Sep 17 00:00:00 2001 From: Jason Williams Date: Tue, 13 May 2014 04:20:57 +0000 Subject: [PATCH] Ensure settings values are strings before saving closes #2736 -reintroduces JSON.stringify for non-string values in api.settings.edit -added a regression test --- core/server/api/settings.js | 6 +++++- core/test/integration/api/api_settings_spec.js | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/core/server/api/settings.js b/core/server/api/settings.js index 16ec0e975d..fe06daed23 100644 --- a/core/server/api/settings.js +++ b/core/server/api/settings.js @@ -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; \ No newline at end of file +module.exports.updateSettingsCache = updateSettingsCache; diff --git a/core/test/integration/api/api_settings_spec.js b/core/test/integration/api/api_settings_spec.js index 014de0da85..402e30564d 100644 --- a/core/test/integration/api/api_settings_spec.js +++ b/core/test/integration/api/api_settings_spec.js @@ -163,4 +163,16 @@ describe('Settings API', function () { done(); }); }); -}); \ No newline at end of file + + 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); + }); +});