Skip to content

Commit fc5f114

Browse files
committed
Merge pull request jsonwebtoken#27 from nakedible-p/patch-1
Fix multiple occurences of `-` or `_` in tokens
2 parents 0b01145 + b884aec commit fc5f114

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

js/jwt.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ window.hextorstr = function (c) {
1111

1212
//this is used to parse base64
1313
function url_base64_decode(str) {
14-
var output = str.replace('-', '+').replace('_', '/');
14+
var output = str.replace(/-/g, '+').replace(/_/g, '/');
1515
switch (output.length % 4) {
1616
case 0:
1717
break;

test/test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,9 @@ describe('jwt library wrapper (jwt.js)', function () {
1616
expect(result.error).to.be.equal(null);
1717
expect(result.result).to.be(true);
1818
});
19+
it('should decode with two underscores', function () {
20+
var result = window.decode('eyI_IjoiYWE_In0');
21+
expect(result.error).to.be.equal(null);
22+
expect(result.result).to.be('{\n "?": "aa?"\n}');
23+
});
1924
});

0 commit comments

Comments
 (0)