diff options
-rw-r--r-- | src/bun.js/bindings/JSBuffer.cpp | 1 | ||||
-rw-r--r-- | test/js/node/buffer.test.js | 13 |
2 files changed, 14 insertions, 0 deletions
diff --git a/src/bun.js/bindings/JSBuffer.cpp b/src/bun.js/bindings/JSBuffer.cpp index ad901b0e4..9227e47b3 100644 --- a/src/bun.js/bindings/JSBuffer.cpp +++ b/src/bun.js/bindings/JSBuffer.cpp @@ -351,6 +351,7 @@ static EncodedJSValue constructFromEncoding(JSGlobalObject* lexicalGlobalObject, case WebCore::BufferEncodingType::utf8: case WebCore::BufferEncodingType::base64: case WebCore::BufferEncodingType::base64url: + case WebCore::BufferEncodingType::hex: case WebCore::BufferEncodingType::ascii: case WebCore::BufferEncodingType::latin1: { result = Bun__encoding__constructFromUTF16(lexicalGlobalObject, view.characters16(), view.length(), static_cast<uint8_t>(encoding)); 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])); +}); |