Skip to content

Commit f6e5e9d

Browse files
author
Marwan Hilmi
committed
Verifying null fix.
1 parent 23f2cda commit f6e5e9d

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ module.exports.verify = function(jwtString, secretOrPublicKey, options, callback
3535
if ((typeof options === 'function') && !callback) callback = options;
3636
if (!options) options = {};
3737

38+
if (!jwtString)
39+
return callback(new JsonWebTokenError('jwt must be provided'));
40+
3841
var parts = jwtString.split('.');
3942
if (parts.length !== 3)
4043
return callback(new JsonWebTokenError('jwt malformed'));

test/jwt.hs.tests.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,13 @@ describe('HS256', function() {
4141
});
4242
});
4343

44+
it('should throw when verifying null', function(done) {
45+
jwt.verify(null, 'secret', function(err, decoded) {
46+
assert.isUndefined(decoded);
47+
assert.isNotNull(err);
48+
done();
49+
});
50+
});
51+
4452
});
4553
});

0 commit comments

Comments
 (0)