diff options
author | 2023-09-17 13:41:52 +0800 | |
---|---|---|
committer | 2023-09-16 22:41:52 -0700 | |
commit | a098c6e5f6d63a9bfd1430798fce4896e26f1a9f (patch) | |
tree | 049f49576262709c87f40435f577d2a6a89e67fa | |
parent | 383d5b55d611b62492178eae4833bf3c134de246 (diff) | |
download | bun-a098c6e5f6d63a9bfd1430798fce4896e26f1a9f.tar.gz bun-a098c6e5f6d63a9bfd1430798fce4896e26f1a9f.tar.zst bun-a098c6e5f6d63a9bfd1430798fce4896e26f1a9f.zip |
feat(encoding): TextDecoder support undefined (#5387)
* feat(encoding): TextDecoder support undefined
* chore: format test file
-rw-r--r-- | src/bun.js/webcore/encoding.zig | 3 | ||||
-rw-r--r-- | test/js/web/encoding/text-decoder.test.js | 5 |
2 files changed, 8 insertions, 0 deletions
diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig index 53933fdb7..8ffbd3fd0 100644 --- a/src/bun.js/webcore/encoding.zig +++ b/src/bun.js/webcore/encoding.zig @@ -702,6 +702,9 @@ pub const TextDecoder = struct { globalThis.throwInvalidArguments("Unsupported encoding label \"{s}\"", .{str.slice()}); return null; } + } else if (arguments[0].isUndefined()) { + // default to utf-8 + decoder.encoding = EncodingLabel.@"UTF-8"; } else { globalThis.throwInvalidArguments("TextDecoder(encoding) label is invalid", .{}); return null; diff --git a/test/js/web/encoding/text-decoder.test.js b/test/js/web/encoding/text-decoder.test.js index 4991cf361..dabdb0936 100644 --- a/test/js/web/encoding/text-decoder.test.js +++ b/test/js/web/encoding/text-decoder.test.js @@ -258,6 +258,11 @@ describe("TextDecoder", () => { const decoder = new TextDecoder("utf-8", { fatal: 10, ignoreBOM: {} }); }).toThrow(); }); + + it("should support undifined", () => { + const decoder = new TextDecoder(undefined); + expect(decoder.encoding).toBe("utf-8"); + }); }); it("truncated sequences", () => { |