diff --git a/index.js b/index.js index dd6d479..ed9db4e 100644 --- a/index.js +++ b/index.js @@ -109,7 +109,7 @@ function JSONCookies (obj) { key = cookies[i] val = JSONCookie(obj[key]) - if (val) { + if (val !== undefined) { obj[key] = val } } diff --git a/test/cookieParser.js b/test/cookieParser.js index 6031823..ab42aa9 100644 --- a/test/cookieParser.js +++ b/test/cookieParser.js @@ -162,6 +162,21 @@ describe('cookieParser.JSONCookie(str)', function () { }) }) +describe('cookieParser.JSONCookies(obj)', function () { + it('should parse JSON cookie values, including falsy ones', function () { + assert.deepEqual(cookieParser.JSONCookies({ + f: 'j:false', + z: 'j:0', + e: 'j:""', + n: 'j:null' + }), { f: false, z: 0, e: '', n: null }) + }) + + it('should leave non-JSON cookie values untouched', function () { + assert.deepEqual(cookieParser.JSONCookies({ a: 'bar', b: 'j:{foo:"bar"}' }), { a: 'bar', b: 'j:{foo:"bar"}' }) + }) +}) + describe('cookieParser.signedCookie(str, secret)', function () { it('should return undefined for non-string arguments', function () { assert.strictEqual(cookieParser.signedCookie(undefined, 'keyboard cat'), undefined)