From e704e99049e1a47e1ce03f9bfcca448760877333 Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Tue, 18 May 2021 23:30:13 +0800 Subject: [PATCH 1/2] stream: allow empty string as source of pipeline Fixes: https://github.com/nodejs/node/issues/38721 --- 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..5e7b6899341d72 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 && typeof obj !== 'string') 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(() => {})); From a0fb263b95ab7f0c9fc3c73cad36bdbd4a75bd0c Mon Sep 17 00:00:00 2001 From: Qingyu Deng Date: Wed, 19 May 2021 09:32:56 +0800 Subject: [PATCH 2/2] fixup!: simplify test condition Co-authored-by: Antoine du Hamel --- lib/internal/streams/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/internal/streams/utils.js b/lib/internal/streams/utils.js index 5e7b6899341d72..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 && typeof obj !== 'string') 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' ||