diff options
author | 2023-09-12 08:27:12 +0800 | |
---|---|---|
committer | 2023-09-11 17:27:12 -0700 | |
commit | c4507a5db33910258278bd6641dcbe34ab33628e (patch) | |
tree | 4a2ea5b4e27ff4be9a24284a1ed8b18eee01a3e9 /test/js/node/buffer.test.js | |
parent | c9a0ea96cd13df39fdfc4c1ebb897453517718f3 (diff) | |
download | bun-c4507a5db33910258278bd6641dcbe34ab33628e.tar.gz bun-c4507a5db33910258278bd6641dcbe34ab33628e.tar.zst bun-c4507a5db33910258278bd6641dcbe34ab33628e.zip |
Fix `Buffer.from` to handle double-byte hex encoding strings (#4933)
Close: #4919
Diffstat (limited to 'test/js/node/buffer.test.js')
-rw-r--r-- | test/js/node/buffer.test.js | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/test/js/node/buffer.test.js b/test/js/node/buffer.test.js index 7c3d16536..afc9cdee8 100644 --- a/test/js/node/buffer.test.js +++ b/test/js/node/buffer.test.js @@ -2572,3 +2572,16 @@ it("construct buffer from UTF16, issue #3914", () => { const buf = Buffer.from(str, "latin1"); expect(buf).toStrictEqual(raw); }); + +it("construct buffer from hex, issue #4919", () => { + const data = "测试63e9f6c4b04fa8c80f3fb0ee"; + + const slice1 = data.substring(0, 2); + const slice2 = data.substring(2); + + const buf1 = Buffer.from(slice1, "hex"); + const buf2 = Buffer.from(slice2, "hex"); + + expect(buf1).toStrictEqual(Buffer.from([])); + expect(buf2).toStrictEqual(Buffer.from([0x63, 0xe9, 0xf6, 0xc4, 0xb0, 0x4f, 0xa8, 0xc8, 0x0f, 0x3f, 0xb0, 0xee])); +}); |