Set null contents to null instead of error throw

Before, if a cookie didn't exist, it would throw an error, not causing permissions/tokens to change to empty values. This fixes that (and #626) by setting the value to undefined instead.
This commit is contained in:
Matthew Taylor 2016-06-30 11:27:46 -04:00
parent 4ef6b22b05
commit 794c3e2cba

View file

@ -15,7 +15,8 @@ var Jar = {
// Return the usable content portion of a signed, compressed cookie generated by
// Django's signing module
// https://github.com/django/django/blob/stable/1.8.x/django/core/signing.py
if (!value) return callback('No value to unsign');
if (typeof value === 'undefined') return callback(null, value);
try {
var b64Data = value.split(':')[0];
var decompress = false;
@ -80,6 +81,8 @@ var Jar = {
if (err) return callback(err);
Jar.unsign(value, function (err, contents) {
if (err) return callback(err);
if (typeof contents === 'undefined') return callback(null, contents);
try {
var data = JSON.parse(contents);
} catch (err) {