Add some sources to the unsign method

This commit is contained in:
Ray Schamp 2016-03-23 10:02:20 -04:00
parent 21dffa73f0
commit 339c23a64e

View file

@ -12,7 +12,9 @@ var pako = require('pako');
*/ */
var Jar = { var Jar = {
unsign: function (value, callback) { unsign: function (value, callback) {
// Return the usable content portion of a signed, compressed cookie // 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 (!value) return callback('No value to unsign');
try { try {
var b64Data = value.split(':')[0]; var b64Data = value.split(':')[0];
@ -23,6 +25,8 @@ var Jar = {
} }
// Django makes its base64 strings url safe by replacing + and / with - and _ respectively // Django makes its base64 strings url safe by replacing + and / with - and _ respectively
// using base64.urlsafe_b64encode
// https://docs.python.org/2/library/base64.html#base64.b64encode
b64Data = b64Data.replace(/[-_]/g, function (c) {return {'-':'+', '_':'/'}[c]; }); b64Data = b64Data.replace(/[-_]/g, function (c) {return {'-':'+', '_':'/'}[c]; });
var strData = atob(b64Data); var strData = atob(b64Data);