mirror of
https://github.com/nodejs/node.git
synced 2026-11-27 17:52:27 -05:00
stream: fix merge handling for object-like sources
merge() treated any final non-iterable object as an options object. That dropped valid from() inputs such as ArrayBuffer, ArrayBufferView, and streamable protocol objects. Fixes: https://github.com/nodejs/node/issues/63355 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> Assisted-by: openai:gpt-5.5 PR-URL: https://github.com/nodejs/node/pull/63356 Backport-PR-URL: https://github.com/nodejs/node/pull/64675 Fixes: https://github.com/nodejs/node/issues/63355 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: René <contact.9a5d6388@renegade334.me.uk>
This commit is contained in:
1 parent
c50d8e49cc
commit
4c9f3edb64
2 files changed
+33
-1
No files matched your search
@@ -8,6 +8,7 @@
|
||||
// ondrain() - backpressure drain utility
|
||||
|
||||
const {
|
||||
ArrayBufferIsView,
|
||||
ArrayBufferPrototypeGetByteLength,
|
||||
ArrayBufferPrototypeSlice,
|
||||
ArrayPrototypeMap,
|
||||
@@ -51,9 +52,12 @@ const {
|
||||
|
||||
const {
|
||||
drainableProtocol,
|
||||
toAsyncStreamable,
|
||||
toStreamable,
|
||||
} = require('internal/streams/iter/types');
|
||||
|
||||
const {
|
||||
isAnyArrayBuffer,
|
||||
isSharedArrayBuffer,
|
||||
} = require('internal/util/types');
|
||||
|
||||
@@ -65,8 +69,12 @@ function isMergeOptions(value) {
|
||||
return (
|
||||
value !== null &&
|
||||
typeof value === 'object' &&
|
||||
!ArrayBufferIsView(value) &&
|
||||
typeof value[toStreamable] !== 'function' &&
|
||||
typeof value[toAsyncStreamable] !== 'function' &&
|
||||
!isAsyncIterable(value) &&
|
||||
!isSyncIterable(value)
|
||||
!isSyncIterable(value) &&
|
||||
!isAnyArrayBuffer(value)
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ const {
|
||||
push,
|
||||
merge,
|
||||
text,
|
||||
toAsyncStreamable,
|
||||
toStreamable,
|
||||
} = require('stream/iter');
|
||||
|
||||
// =============================================================================
|
||||
@@ -162,6 +164,27 @@ async function testMergeStringSources() {
|
||||
assert.ok(combined.includes('world'));
|
||||
}
|
||||
|
||||
// merge() accepts object-like sources that are normalized via from()
|
||||
async function testMergeObjectLikeSources() {
|
||||
const arrayBuffer = new TextEncoder().encode('abc').buffer;
|
||||
const dataView = new DataView(new TextEncoder().encode('def').buffer);
|
||||
const streamable = {
|
||||
[toStreamable]() {
|
||||
return 'ghi';
|
||||
},
|
||||
};
|
||||
const asyncStreamable = {
|
||||
[toAsyncStreamable]() {
|
||||
return Promise.resolve('jkl');
|
||||
},
|
||||
};
|
||||
|
||||
assert.strictEqual(await text(merge(arrayBuffer)), 'abc');
|
||||
assert.strictEqual(await text(merge(dataView)), 'def');
|
||||
assert.strictEqual(await text(merge(streamable)), 'ghi');
|
||||
assert.strictEqual(await text(merge(asyncStreamable)), 'jkl');
|
||||
}
|
||||
|
||||
Promise.all([
|
||||
testMergeTwoSources(),
|
||||
testMergeSingleSource(),
|
||||
@@ -172,4 +195,5 @@ Promise.all([
|
||||
testMergeConsumerBreak(),
|
||||
testMergeSignalMidIteration(),
|
||||
testMergeStringSources(),
|
||||
testMergeObjectLikeSources(),
|
||||
]).then(common.mustCall());
|
||||
Reference in new issue
Block a user