Skip to content

Commit

Permalink
fix: handle SharedArrayBuffer correctly (#2466)
Browse files Browse the repository at this point in the history
* fix: handle SharedArrayBuffer correctly

* format

* test: add

* fix: test

* fixup

* use ArrayBuffer.isView

* fixup

* fixup

* test: add Request

* fixup
  • Loading branch information
tsctx committed Nov 27, 2023
1 parent c182c32 commit 56efa96
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 1 addition & 5 deletions lib/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
7 changes: 7 additions & 0 deletions test/fetch/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -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())
7 changes: 7 additions & 0 deletions test/fetch/response.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]')
})

0 comments on commit 56efa96

Please sign in to comment.