Skip to content

Commit 8449d4f

Browse files
committed
decoder function rectified
1 parent 9465d54 commit 8449d4f

File tree

4 files changed

+8
-3
lines changed

4 files changed

+8
-3
lines changed

src/cjs/browser.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const HEX_CODEPOINTS = Array(256)
1212
return index < 0 ? undefined : index < 16 ? index : index - 6;
1313
});
1414
const ENCODER = new TextEncoder();
15-
const DECODER = new TextDecoder("ascii");
15+
const DECODER = new TextDecoder();
1616
function toUtf8(bytes) {
1717
return DECODER.decode(bytes);
1818
}

src/mjs/browser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const HEX_CODEPOINTS = Array(256)
99
return index < 0 ? undefined : index < 16 ? index : index - 6;
1010
});
1111
const ENCODER = new TextEncoder();
12-
const DECODER = new TextDecoder("ascii");
12+
const DECODER = new TextDecoder();
1313
export function toUtf8(bytes) {
1414
return DECODER.decode(bytes);
1515
}

ts_src/browser.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const HEX_CODEPOINTS: (number | undefined)[] = Array(256)
99
return index < 0 ? undefined : index < 16 ? index : index - 6;
1010
});
1111
const ENCODER = new TextEncoder();
12-
const DECODER = new TextDecoder("ascii");
12+
const DECODER = new TextDecoder();
1313

1414
export function toUtf8(bytes: Uint8Array): string {
1515
return DECODER.decode(bytes);

ts_src/tests.spec.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ const bytes3 = f([0x21, 0x7e]);
1818
const utf8 = "!~";
1919
const longBytes2 = new Uint8Array(513).fill(0x61);
2020
const longUtf8 = "a".repeat(513);
21+
const testBytes = f([
22+
227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175,
23+
]);
24+
const str = "こんにちは";
2125

2226
const brokenHexes = [
2327
[" ff00", f([]), "leading space"],
@@ -45,6 +49,7 @@ describe(`Uint8Array tools`, () => {
4549
});
4650
it(`should output utf8 with toUtf8`, () => {
4751
expect(tools.toUtf8(bytes3)).toEqual(utf8);
52+
expect(tools.toUtf8(testBytes)).toEqual(str);
4853
expect(tools.toUtf8(longBytes2)).toEqual(longUtf8);
4954
expect((tools.toUtf8 as any)()).toEqual("");
5055
});

0 commit comments

Comments
 (0)