{{ message }}
Repository navigation
Conversation
res.send detects DataView via ArrayBuffer.isView() and sets the binary Content-Type, but the chunk then falls through to Buffer.from(chunk, encoding). Buffer.from(dataView) returns an empty Buffer, so a DataView-bodied response went out as 200 with Content-Length: 0 and no payload. Convert a DataView to a Buffer over its exact byte range right after the Content-Type decision, using Buffer.from(buffer, byteOffset, byteLength). Typed arrays (Uint8Array, Uint16Array, …) continue through the existing fast path untouched, so compat with Uint16Array raised on #7433 is preserved. Two regression tests: - DataView over the whole backing buffer sends the full bytes and the correct Content-Length. - DataView with explicit byteOffset and byteLength sends only its slice (verifying that we don't send the surrounding bytes). All 1263 existing tests still pass. Fixes #7510.
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Bug (fixes #7510)
res.senddetectsDataViewviaArrayBuffer.isView()and sets the binaryContent-Type, but the chunk then falls through toBuffer.from(chunk, encoding).Buffer.from(dataView)returns an emptyBuffer, so a DataView-bodied response went out as200withContent-Length: 0and no payload.Repro:
Fix
Convert a
DataViewto aBufferover its exact byte range right after theContent-Typedecision, usingBuffer.from(buffer, byteOffset, byteLength). Typed arrays (Uint8Array,Uint16Array, …) continue through the existing fast path untouched, so the Uint16Array compat raised on #7433 is preserved.Tests
Two regression tests added to
test/res.send.js:Content-Length: 3and body"hey".[0xff, 0x68, 0x65, 0x79, 0xff]withnew DataView(buf, 1, 3)— asserts the surrounding0xffbytes don't leak into the response.All 1263 existing tests still pass.
npm run lintis clean.