aboutsummaryrefslogtreecommitdiff
path: root/test/js/web/encoding/text-decoder.test.js
diff options
context:
space:
mode:
authorGravatar WingLim <winglims@gmail.com> 2023-09-21 09:44:05 +0800
committerGravatar GitHub <noreply@github.com> 2023-09-20 18:44:05 -0700
commit5f66b4e729105286863a13955b1ed8897b45210e (patch)
treecec6d517bac47ccd52f7e8aeef5f99fb98412008 /test/js/web/encoding/text-decoder.test.js
parent7319142fd866d8314364d769f401a492892f7d63 (diff)
downloadbun-5f66b4e729105286863a13955b1ed8897b45210e.tar.gz
bun-5f66b4e729105286863a13955b1ed8897b45210e.tar.zst
bun-5f66b4e729105286863a13955b1ed8897b45210e.zip
feat(encoding): support BOM detection (#5550)
* fix(encoding): export `getIgnoreBOM` * feat(encoding): support ignoreBOM * fix(encoding): not replace BOM to 0xFFFD * chore: use strict equal
Diffstat (limited to 'test/js/web/encoding/text-decoder.test.js')
-rw-r--r--test/js/web/encoding/text-decoder.test.js25
1 files changed, 24 insertions, 1 deletions
diff --git a/test/js/web/encoding/text-decoder.test.js b/test/js/web/encoding/text-decoder.test.js
index dabdb0936..de71fb351 100644
--- a/test/js/web/encoding/text-decoder.test.js
+++ b/test/js/web/encoding/text-decoder.test.js
@@ -250,7 +250,7 @@ describe("TextDecoder", () => {
it("constructor should set values", () => {
const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: false });
expect(decoder.fatal).toBe(true);
- // expect(decoder.ignoreBOM).toBe(false); // currently the getter for ignoreBOM doesn't work and always returns undefined
+ expect(decoder.ignoreBOM).toBe(false);
});
it("should throw on invalid input", () => {
@@ -265,6 +265,29 @@ describe("TextDecoder", () => {
});
});
+describe("TextDecoder ignoreBOM", () => {
+
+ it.each([
+ {
+ encoding: 'utf-8',
+ bytes: [0xEF, 0xBB, 0xBF, 0x61, 0x62, 0x63]
+ },
+ {
+ encoding: 'utf-16le',
+ bytes: [0xFF, 0xFE, 0x61, 0x00, 0x62, 0x00, 0x63, 0x00]
+ }
+ ])('should ignoreBOM for: %o', ({encoding, bytes}) => {
+ const BOM = '\uFEFF';
+ const array = new Uint8Array(bytes);
+
+ const decoder_ignore_bom = new TextDecoder(encoding, {ignoreBOM: true});
+ expect(decoder_ignore_bom.decode(array)).toStrictEqual(`${BOM}abc`);
+
+ const decoder_not_ignore_bom = new TextDecoder(encoding, {ignoreBOM: false});
+ expect(decoder_not_ignore_bom.decode(array)).toStrictEqual('abc');
+ });
+});
+
it("truncated sequences", () => {
const assert_equals = (a, b) => expect(a).toBe(b);