Skip to content

Commit

Permalink
this is a major change, it changes the default encoding from binary t…
Browse files Browse the repository at this point in the history
…o utf8
  • Loading branch information
jfromaniello committed Mar 6, 2015
1 parent 82dd249 commit 92d33bd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"url": "https://github.com/auth0/node-jsonwebtoken/issues"
},
"dependencies": {
"jws": "~1.0.1"
"jws": "~2.0.0"
},
"devDependencies": {
"atob": "~1.1.2",
Expand Down
18 changes: 17 additions & 1 deletion test/encoding.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,27 @@ var atob = require('atob');

describe('encoding', function() {

function b64_to_utf8 (str) {
return decodeURIComponent(escape(atob( str )));
}

it('should properly encode the token', function () {
var expected = 'José';
var token = jwt.sign({ name: expected }, 'shhhhh');
var decoded_name = JSON.parse(atob(token.split('.')[1])).name;
var decoded_name = JSON.parse(b64_to_utf8(token.split('.')[1])).name;
expect(decoded_name).to.equal(expected);
});

it('should return the same result when decoding', function () {
var username = '測試';

var token = jwt.sign({
username: username
}, 'test');

var payload = jwt.verify(token, 'test');

expect(payload.username).to.equal(username);
});

});

1 comment on commit 92d33bd

@antonioreyna
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what could you use instead of escape which is deprecated?

Please sign in to comment.