Skip to content

Commit

Permalink
Fix utf-8 decoder
Browse files Browse the repository at this point in the history
  • Loading branch information
RealDolos committed May 12, 2018
1 parent 25fcda6 commit ed9cb3b
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion browser/decode.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function utf8Read(view, offset, length) {
}
if ((byte & 0xe0) === 0xc0) {
string += String.fromCharCode(
((byte & 0x0f) << 6) |
((byte & 0x1f) << 6) |
(view.getUint8(++i) & 0x3f)
);
continue;
Expand Down
2 changes: 1 addition & 1 deletion dist/notepack.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/notepack.js.map

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,17 @@ describe('notepack (browser build)', function() {
expect(notepack.encode(obj)).to.deep.equal(notepack.encode('c'));
});

it('utf-8', function() {
// 1-byte
expect(notepack.decode(notepack.encode('äß'))).to.equal('äß');
// 2-byte
expect(notepack.decode(notepack.encode('עִבְרִית'))).to.equal('עִבְרִית');
// 3-byte
expect(notepack.decode(notepack.encode('\u13DA'))).to.equal('\u13DA');
// 4-byte
expect(notepack.decode(notepack.encode('🌐'))).to.equal('🌐');
});

it('all formats', function () {
this.timeout(20000);
var expected = {
Expand Down

0 comments on commit ed9cb3b

Please sign in to comment.