From 34054a32c0f5d9733d18e5a677b2383aaa09fd08 Mon Sep 17 00:00:00 2001 From: Katharina Irrgang Date: Thu, 26 Oct 2017 13:54:18 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20=20Theme=20name=20is=20point=20n?= =?UTF-8?q?umber=20(#9184)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit closes #9182 - e.g. "1.4" - extend settings cache to ensure we return strings for numbers and floating point numbers --- core/server/settings/cache.js | 2 +- core/test/unit/settings/cache_spec.js | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/core/server/settings/cache.js b/core/server/settings/cache.js index 336ca4ee85..b07d109c30 100644 --- a/core/server/settings/cache.js +++ b/core/server/settings/cache.js @@ -50,7 +50,7 @@ module.exports = { // Default behaviour is to try to resolve the value and return that try { // CASE: if a string contains a number e.g. "1", JSON.parse will auto convert into integer - if (settingsCache[key].value.match(/^\d+$/)) { + if (!isNaN(Number(settingsCache[key].value))) { return settingsCache[key].value; } diff --git a/core/test/unit/settings/cache_spec.js b/core/test/unit/settings/cache_spec.js index b59c1499ff..9effcff707 100644 --- a/core/test/unit/settings/cache_spec.js +++ b/core/test/unit/settings/cache_spec.js @@ -10,6 +10,11 @@ describe('UNIT: settings cache', function () { (typeof cache.get('key1')).should.eql('string'); }); + it('does not auto convert string into number: float', function () { + cache.set('key1', {value: '1.4'}); + (typeof cache.get('key1')).should.eql('string'); + }); + it('stringified JSON get\'s parsed', function () { cache.set('key2', {value: '{"a":"1","b":"hallo","c":{"d":[]},"e":2}'}); (typeof cache.get('key2')).should.eql('object');