From 4131f94ca84b7ad536794508c41c7c2014e5816e Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Tue, 18 May 2021 23:30:13 +0800 Subject: [PATCH] stream: allow empty string as source of pipeline Fixes: https://github.com/nodejs/node/issues/38721 PR-URL: https://github.com/nodejs/node/pull/38723 Reviewed-By: Ruben Bridgewater Reviewed-By: Antoine du Hamel Reviewed-By: Robert Nagy Reviewed-By: James M Snell Reviewed-By: Luigi Pinca Reviewed-By: Zijian Liu Reviewed-By: Darshan Sen --- lib/internal/streams/utils.js | 2 +- .../test-stream-pipeline-with-empty-string.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 test/parallel/test-stream-pipeline-with-empty-string.js diff --git a/lib/internal/streams/utils.js b/lib/internal/streams/utils.js index b6e744250799c6..62eea022685e18 100644 --- a/lib/internal/streams/utils.js +++ b/lib/internal/streams/utils.js @@ -20,7 +20,7 @@ function isStream(obj) { } function isIterable(obj, isAsync) { - if (!obj) return false; + if (obj == null) return false; if (isAsync === true) return typeof obj[SymbolAsyncIterator] === 'function'; if (isAsync === false) return typeof obj[SymbolIterator] === 'function'; return typeof obj[SymbolAsyncIterator] === 'function' || diff --git a/test/parallel/test-stream-pipeline-with-empty-string.js b/test/parallel/test-stream-pipeline-with-empty-string.js new file mode 100644 index 00000000000000..8818f38e8596f2 --- /dev/null +++ b/test/parallel/test-stream-pipeline-with-empty-string.js @@ -0,0 +1,18 @@ +'use strict'; + +const common = require('../common'); +const { + pipeline, + PassThrough +} = require('stream'); + + +async function runTest() { + await pipeline( + '', + new PassThrough({ objectMode: true }), + common.mustCall(() => { }) + ); +} + +runTest().then(common.mustCall(() => {}));