diff options
-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", () => { |