aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ai Hoshino <ambiguous404@gmail.com> 2023-07-22 13:01:26 +0800
committerGravatar GitHub <noreply@github.com> 2023-07-21 22:01:26 -0700
commit1ecd9f8a18da1af9f2090791b15a18ff3e68411d (patch)
tree9c093c080824cfa6d01c94dc95858534c57a8f19
parent2323f5d08d4c1d85d65ac89460dac592a7514fbd (diff)
downloadbun-1ecd9f8a18da1af9f2090791b15a18ff3e68411d.tar.gz
bun-1ecd9f8a18da1af9f2090791b15a18ff3e68411d.tar.zst
bun-1ecd9f8a18da1af9f2090791b15a18ff3e68411d.zip
handle `latin1` in `Bun__encoding__toString`. (#3739)
Close: #3738
-rw-r--r--src/bun.js/webcore/encoding.zig1
-rw-r--r--test/js/node/string_decoder/string-decoder.test.js10
2 files changed, 11 insertions, 0 deletions
diff --git a/src/bun.js/webcore/encoding.zig b/src/bun.js/webcore/encoding.zig
index 41a27ccd4..7a0188aab 100644
--- a/src/bun.js/webcore/encoding.zig
+++ b/src/bun.js/webcore/encoding.zig
@@ -828,6 +828,7 @@ pub const Encoder = struct {
.hex => toString(input, len, globalObject, .hex),
.base64 => toString(input, len, globalObject, .base64),
.base64url => toString(input, len, globalObject, .base64url),
+ .latin1 => toString(input, len, globalObject, .latin1),
// treat everything else as utf8
else => toString(input, len, globalObject, .utf8),
diff --git a/test/js/node/string_decoder/string-decoder.test.js b/test/js/node/string_decoder/string-decoder.test.js
index aba73401a..5e8463955 100644
--- a/test/js/node/string_decoder/string-decoder.test.js
+++ b/test/js/node/string_decoder/string-decoder.test.js
@@ -250,3 +250,13 @@ it("invalid utf-8 input, pr #3562", () => {
output += decoder.end();
expect(output).toStrictEqual("\uFFFD\uFFFD");
});
+
+it("decoding latin1, issue #3738", () => {
+ const decoder = new RealStringDecoder("latin1");
+ let output = "";
+ output += decoder.write(Buffer.from("DD", "hex"));
+ output += decoder.write(Buffer.from("59", "hex"));
+ output += decoder.write(Buffer.from("DE", "hex"));
+ output += decoder.end();
+ expect(output).toStrictEqual("ÝYÞ");
+});