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:
parent
b081ae34b5
commit
a61e6e7cc2
2 changed files with 26 additions and 0 deletions
|
@ -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;
|
||||
|
|
21
core/test/unit/settings/cache_spec.js
Normal file
21
core/test/unit/settings/cache_spec.js
Normal 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);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue