diff options
author | 2023-08-10 00:45:50 +0800 | |
---|---|---|
committer | 2023-08-09 09:45:50 -0700 | |
commit | 385d440694a95bc4bfee25daa602c5c4363b6423 (patch) | |
tree | b2766ac8df676f6c22b5390a009e766f381346ce /test/js/node/buffer.test.js | |
parent | b3019270c9640a60f7a30f172cea10e310baf3b6 (diff) | |
download | bun-385d440694a95bc4bfee25daa602c5c4363b6423.tar.gz bun-385d440694a95bc4bfee25daa602c5c4363b6423.tar.zst bun-385d440694a95bc4bfee25daa602c5c4363b6423.zip |
Fix constructing buffer from a UTF16 string with the Latin1 encoding. (#4086)
Close: #3914
Diffstat (limited to 'test/js/node/buffer.test.js')
-rw-r--r-- | test/js/node/buffer.test.js | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/test/js/node/buffer.test.js b/test/js/node/buffer.test.js index 129ceb02b..834536020 100644 --- a/test/js/node/buffer.test.js +++ b/test/js/node/buffer.test.js @@ -2552,3 +2552,15 @@ it("write alias", () => { shouldBeSame("writeBigUint64BE", "writeBigUInt64BE", BigInt(1000)); shouldBeSame("writeBigUint64LE", "writeBigUInt64LE", BigInt(1000)); }); + +it("construct buffer from UTF16, issue #3914", () => { + const raw = Buffer.from([0, 104, 0, 101, 0, 108, 0, 108, 0, 111]); + const data = new Uint16Array(raw); + + const decoder = new TextDecoder("UTF-16"); + const str = decoder.decode(data); + expect(str).toStrictEqual("\x00h\x00e\x00l\x00l\x00o"); + + const buf = Buffer.from(str, "latin1"); + expect(buf).toStrictEqual(raw); +}); |