diff --git a/lib/fetch/response.js b/lib/fetch/response.js index 5d23475f14e..73386123e33 100644 --- a/lib/fetch/response.js +++ b/lib/fetch/response.js @@ -514,11 +514,7 @@ webidl.converters.XMLHttpRequestBodyInit = function (V) { return webidl.converters.Blob(V, { strict: false }) } - if ( - types.isAnyArrayBuffer(V) || - types.isTypedArray(V) || - types.isDataView(V) - ) { + if (types.isArrayBuffer(V) || types.isTypedArray(V) || types.isDataView(V)) { return webidl.converters.BufferSource(V) } diff --git a/test/fetch/request.js b/test/fetch/request.js index 4f66de4ec73..db2c8e868b6 100644 --- a/test/fetch/request.js +++ b/test/fetch/request.js @@ -504,4 +504,11 @@ test('keys to object prototypes method', (t) => { t.ok(typeof request.method === 'string') }) +// https://github.com/nodejs/undici/issues/2465 +test('Issue#2465', async (t) => { + t.plan(1) + const request = new Request('http://localhost', { body: new SharedArrayBuffer(0), method: 'POST' }) + t.equal(await request.text(), '[object SharedArrayBuffer]') +}) + teardown(() => process.exit()) diff --git a/test/fetch/response.js b/test/fetch/response.js index 2342f0927ff..422c7ef2e02 100644 --- a/test/fetch/response.js +++ b/test/fetch/response.js @@ -248,3 +248,10 @@ test('constructing Response with third party FormData body', async (t) => { t.equal(contentType[0], 'multipart/form-data; boundary') t.ok((await res.text()).startsWith(`--${contentType[1]}`)) }) + +// https://github.com/nodejs/undici/issues/2465 +test('Issue#2465', async (t) => { + t.plan(1) + const response = new Response(new SharedArrayBuffer(0)) + t.equal(await response.text(), '[object SharedArrayBuffer]') +})