0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

🐛 fix settings cache (#8506)

closes #8505

- cache.get(..) auto converted "1" to integer
This commit is contained in:
Katharina Irrgang 2017-06-04 12:52:22 +02:00 committed by Aileen Nowak
parent b081ae34b5
commit a61e6e7cc2
2 changed files with 26 additions and 0 deletions

View file

@ -49,6 +49,11 @@ 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+$/)) {
return settingsCache[key].value;
}
return JSON.parse(settingsCache[key].value);
} catch (err) {
return settingsCache[key].value;

View file

@ -0,0 +1,21 @@
var rewire = require('rewire'),
should = require('should'),
cache = rewire('../../../server/settings/cache');
should.equal(true, true);
describe('UNIT: settings cache', function () {
it('does not auto convert string into number', function () {
cache.set('key1', {value: '1'});
(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');
cache.get('key2').a.should.eql('1');
cache.get('key2').b.should.eql('hallo');
cache.get('key2').c.should.eql({d: []});
cache.get('key2').e.should.eql(2);
});
});