diff --git a/lib/tls.js b/lib/tls.js index 9bdf1d8f33df9c..17ad9fb24a0898 100644 --- a/lib/tls.js +++ b/lib/tls.js @@ -56,6 +56,7 @@ const internalUtil = require('internal/util'); internalUtil.assertCrypto(); const { isArrayBufferView, + isDataView, isUint8Array, } = require('internal/util/types'); @@ -149,6 +150,11 @@ exports.convertALPNProtocols = function convertALPNProtocols(protocols, out) { } else if (Buffer.isBuffer(protocols) || isUint8Array(protocols)) { // Copy new buffer not to be modified by user. out.ALPNProtocols = Buffer.from(protocols); + } else if (isDataView(protocols)) { + out.ALPNProtocols = Buffer.from(protocols.buffer.slice( + protocols.byteOffset, + protocols.byteOffset + protocols.byteLength + )); } else if (isArrayBufferView(protocols)) { out.ALPNProtocols = Buffer.from(protocols.slice().buffer); } diff --git a/test/parallel/test-tls-basic-validations.js b/test/parallel/test-tls-basic-validations.js index e5ce099d1dbd5f..4a3aab314680ac 100644 --- a/test/parallel/test-tls-basic-validations.js +++ b/test/parallel/test-tls-basic-validations.js @@ -103,8 +103,11 @@ assert.throws( const inputBuffer = Buffer.from(arrayBufferViewStr.repeat(8), 'utf8'); for (const expectView of common.getArrayBufferViews(inputBuffer)) { const out = {}; + const expected = Buffer.from(expectView.buffer.slice(), + expectView.byteOffset, + expectView.byteLength); tls.convertALPNProtocols(expectView, out); - assert(out.ALPNProtocols.equals(Buffer.from(expectView.slice().buffer))); + assert(out.ALPNProtocols.equals(expected)); } }