diff --git a/lib/internal/http2/core.js b/lib/internal/http2/core.js index 751e8b189b2462..32e02aa3f6c640 100644 --- a/lib/internal/http2/core.js +++ b/lib/internal/http2/core.js @@ -1444,9 +1444,9 @@ class Http2Session extends EventEmitter { } if (payload) { validateBuffer(payload, 'payload'); - } - if (payload && payload.length !== 8) { - throw new ERR_HTTP2_PING_LENGTH(); + if (payload.byteLength !== 8) { + throw new ERR_HTTP2_PING_LENGTH(); + } } validateFunction(callback, 'callback'); diff --git a/test/parallel/test-http2-ping.js b/test/parallel/test-http2-ping.js index 9a6b30194d0c30..90ef57e03ccf59 100644 --- a/test/parallel/test-http2-ping.js +++ b/test/parallel/test-http2-ping.js @@ -64,11 +64,11 @@ server.listen(0, common.mustCall(() => { }))); } { - const payload = Buffer.from('abcdefgi'); + const payload = new Uint16Array([1, 2, 3, 4]); assert(client.ping(payload, common.mustCall((err, duration, ret) => { assert.strictEqual(err, null); assert.strictEqual(typeof duration, 'number'); - assert.deepStrictEqual(payload, ret); + assert.deepStrictEqual(payload.buffer, ret.buffer); }))); } @@ -99,7 +99,8 @@ server.listen(0, common.mustCall(() => { { const shortPayload = Buffer.from('abcdefg'); const longPayload = Buffer.from('abcdefghi'); - [shortPayload, longPayload].forEach((payloadWithInvalidLength) => + const mismatchedPayload = new Uint32Array(8); + [shortPayload, longPayload, mismatchedPayload].forEach((payloadWithInvalidLength) => assert.throws( () => client.ping(payloadWithInvalidLength), {