aboutsummaryrefslogtreecommitdiff
path: root/test/js/web/encoding/text-decoder.test.js
diff options
context:
space:
mode:
authorGravatar Dylan Conway <35280289+dylan-conway@users.noreply.github.com> 2023-09-05 17:53:31 -0700
committerGravatar GitHub <noreply@github.com> 2023-09-05 17:53:31 -0700
commit70a5cfe9087c9836cef06ee3560f6111ed2fe18e (patch)
treea8968f64234384cda482ae7e85beb7a9c3f4e7e6 /test/js/web/encoding/text-decoder.test.js
parent1bd5b245b8a55353e60a2decad507ef8014be044 (diff)
downloadbun-70a5cfe9087c9836cef06ee3560f6111ed2fe18e.tar.gz
bun-70a5cfe9087c9836cef06ee3560f6111ed2fe18e.tar.zst
bun-70a5cfe9087c9836cef06ee3560f6111ed2fe18e.zip
fix text decode trim (#4495)
* remove trim * separate function * a test * trim when `stream` is true --------- Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
Diffstat (limited to 'test/js/web/encoding/text-decoder.test.js')
-rw-r--r--test/js/web/encoding/text-decoder.test.js14
1 files changed, 14 insertions, 0 deletions
diff --git a/test/js/web/encoding/text-decoder.test.js b/test/js/web/encoding/text-decoder.test.js
index 8ec097f31..4991cf361 100644
--- a/test/js/web/encoding/text-decoder.test.js
+++ b/test/js/web/encoding/text-decoder.test.js
@@ -233,6 +233,20 @@ describe("TextDecoder", () => {
}).toThrow(TypeError);
});
+ it("should not trim invalid byte sequences when fatal is false", () => {
+ const buf = Buffer.from([77, 97, 110, 32, 208, 129, 240, 164, 173]);
+ const received = new TextDecoder("utf-8").decode(buf);
+ const expected = "Man Ё\ufffd";
+ expect(received).toBe(expected);
+ });
+
+ it("should trim when stream is true", () => {
+ const buf = Buffer.from([77, 97, 110, 32, 208, 129, 240, 164, 173]);
+ const received = new TextDecoder("utf-8").decode(buf, { stream: true });
+ const expected = "Man Ё";
+ expect(received).toBe(expected);
+ });
+
it("constructor should set values", () => {
const decoder = new TextDecoder("utf-8", { fatal: true, ignoreBOM: false });
expect(decoder.fatal).toBe(true);