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:
Trivikram Kamat authored and Antoine du Hamel committed 2026-08-06 11:32:59 +02:00
1 parent c50d8e49cc
commit 4c9f3edb64
2 files changed
+33 -1

No files matched your search

+9 -1
View File
@@ -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());