Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stream.pipeline does not accept zero-length string as a valid first argument #38721

Closed
carlansley opened this issue May 18, 2021 · 1 comment
Closed
Labels
stream Issues and PRs related to the stream subsystem.

Comments

@carlansley
Copy link

carlansley commented May 18, 2021

  • Version: v16.1.0
  • Platform: Darwin Carls-iMac-Pro.local 20.4.0 Darwin Kernel Version 20.4.0: Thu Apr 22 21:46:47 PDT 2021; root:xnu-7195.101.2~1/RELEASE_X86_64 x86_64
  • Subsystem: stream

What steps will reproduce the bug?

This corner-case issue is another continuation of #36437. Although Iterables are now supported, zero-length strings are not.

const stream = require("stream");

async function main() {
    await stream.pipeline(
        /*stream1*/ '',
        /*stream2*/ new stream.PassThrough({ objectMode: true }),
        /*callback*/ () => { console.log("done"); });
}

main().catch(e => console.error(e));

How often does it reproduce? Is there a required condition?

Reproduces in all versions of Node tested, 16+.

What is the expected behavior?

For a zero-length string to be able to be used as a source/first argument. Strings with non-zero lengths work correctly.

What do you see instead?

TypeError [ERR_INVALID_ARG_TYPE]: The "source" argument must be of type function or an instance of Stream, Iterable, or AsyncIterable. Received type string ('')
    at Function.pipeline (internal/streams/pipeline.js:202:15)
    at main (REPL8:2:18)
    at REPL10:1:1
    at Script.runInThisContext (vm.js:133:18)
    at REPLServer.defaultEval (repl.js:486:29)
    at bound (domain.js:416:15)
    at REPLServer.runBound [as eval] (domain.js:427:12)
    at REPLServer.onLine (repl.js:819:10)
    at REPLServer.emit (events.js:388:22)
    at REPLServer.emit (domain.js:470:12) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Additional information

@Ayase-252 Ayase-252 added the stream Issues and PRs related to the stream subsystem. label May 18, 2021
@Ayase-252
Copy link
Member

It seems that empty string "" get rejected here, while string is an Iterable by definition.

if (!obj) return false;

Opening a PR to fix.

Ayase-252 added a commit to Ayase-252/node that referenced this issue May 18, 2021
danielleadams pushed a commit that referenced this issue May 31, 2021
Fixes: #38721

PR-URL: #38723
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants