Add coverage for odd string lengths in Uint8Array.prototype.setFromHex

V8 doesn't handle this correctly for zero length typed arrays.
This commit is contained in:
André Bargull 2025-05-12 15:57:59 +02:00 committed by Philip Chimento
parent 8649d5e117
commit 7c9314b06b

View File

@ -0,0 +1,40 @@
// Copyright (C) 2025 André Bargull. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-uint8array.prototype.setfromhex
description: >
Throws a SyntaxError when the string length is odd.
info: |
Uint8Array.prototype.setFromHex ( string )
...
7. Let result be FromHex(string, byteLength).
...
13. If result.[[Error]] is not none, then
a. Throw result.[[Error]].
...
FromHex ( string [ , maxLength ] )
...
5. If length modulo 2 is not 0, then
a. Let error be a new SyntaxError exception.
b. Return the Record { [[Read]]: read, [[Bytes]]: bytes, [[Error]]: error }.
...
features: [TypedArray, uint8array-base64]
---*/
var zeroLength = new Uint8Array(0);
assert.throws(SyntaxError, function() {
zeroLength.setFromHex("1")
}, "Uint8Array has length 0");
var nonZeroLength = new Uint8Array(1);
assert.throws(SyntaxError, function() {
nonZeroLength.setFromHex("1")
}, "Uint8Array has length >0");