Skip to content

Commit 56efa96

Browse files
authoredNov 27, 2023
fix: handle SharedArrayBuffer correctly (#2466)
* fix: handle SharedArrayBuffer correctly * format * test: add * fix: test * fixup * use ArrayBuffer.isView * fixup * fixup * test: add Request * fixup
1 parent c182c32 commit 56efa96

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed
 

‎lib/fetch/response.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -514,11 +514,7 @@ webidl.converters.XMLHttpRequestBodyInit = function (V) {
514514
return webidl.converters.Blob(V, { strict: false })
515515
}
516516

517-
if (
518-
types.isAnyArrayBuffer(V) ||
519-
types.isTypedArray(V) ||
520-
types.isDataView(V)
521-
) {
517+
if (types.isArrayBuffer(V) || types.isTypedArray(V) || types.isDataView(V)) {
522518
return webidl.converters.BufferSource(V)
523519
}
524520

‎test/fetch/request.js

+7
Original file line numberDiff line numberDiff line change
@@ -504,4 +504,11 @@ test('keys to object prototypes method', (t) => {
504504
t.ok(typeof request.method === 'string')
505505
})
506506

507+
// https://github.com/nodejs/undici/issues/2465
508+
test('Issue#2465', async (t) => {
509+
t.plan(1)
510+
const request = new Request('http://localhost', { body: new SharedArrayBuffer(0), method: 'POST' })
511+
t.equal(await request.text(), '[object SharedArrayBuffer]')
512+
})
513+
507514
teardown(() => process.exit())

‎test/fetch/response.js

+7
Original file line numberDiff line numberDiff line change
@@ -248,3 +248,10 @@ test('constructing Response with third party FormData body', async (t) => {
248248
t.equal(contentType[0], 'multipart/form-data; boundary')
249249
t.ok((await res.text()).startsWith(`--${contentType[1]}`))
250250
})
251+
252+
// https://github.com/nodejs/undici/issues/2465
253+
test('Issue#2465', async (t) => {
254+
t.plan(1)
255+
const response = new Response(new SharedArrayBuffer(0))
256+
t.equal(await response.text(), '[object SharedArrayBuffer]')
257+
})

0 commit comments

Comments
 (0)
Please sign in to comment.