1
0
mirror of https://github.com/Ylianst/MeshAgent synced 2026-01-09 03:53:26 +00:00

Updated Buffer.from(), to allow hex encodings to start with 0x

This commit is contained in:
Bryan Roe
2019-01-18 16:20:03 -08:00
parent d64dfb5504
commit b33c9ee4b8
2 changed files with 11 additions and 1 deletions

View File

@@ -355,6 +355,11 @@ duk_ret_t ILibDuktape_Polyfills_Buffer_from(duk_context *ctx)
}
else if (strcmp(encoding, "hex") == 0)
{
if (ILibString_StartsWith(str, (int)strlength, "0x", 2) != 0)
{
str += 2;
strlength -= 2;
}
buffer = duk_push_fixed_buffer(ctx, strlength / 2);
bufferLen = util_hexToBuf(str, (int)strlength, buffer);
duk_push_buffer_object(ctx, -1, 0, bufferLen, DUK_BUFOBJ_NODEJS_BUFFER);