mirror of
https://github.com/hanzoai/node-jsonwebtoken.git
synced 2026-09-24 17:00:48 +00:00
Check payload is not null when decoded. (#444)
* Check payload is not null when decoded. Fixed "Cannot read property 'nbf' of null" * Condition on obj !== null for clarity * Added test for decoding null token
This commit is contained in:
committed by
Eduardo Diaz
parent
cc7c41b109
commit
e50764b070
@@ -10,7 +10,7 @@ module.exports = function (jwt, options) {
|
||||
if(typeof payload === 'string') {
|
||||
try {
|
||||
var obj = JSON.parse(payload);
|
||||
if(typeof obj === 'object') {
|
||||
if(obj !== null && typeof obj === 'object') {
|
||||
payload = obj;
|
||||
}
|
||||
} catch (e) { }
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
var jwt = require('../index');
|
||||
var expect = require('chai').expect;
|
||||
var atob = require('atob');
|
||||
|
||||
describe('decoding', function() {
|
||||
|
||||
it('should not crash when decoding a null token', function () {
|
||||
var decoded = jwt.decode("null");
|
||||
expect(decoded).to.equal(null);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user