Skip to content

Conversation

@killagu
Copy link
Contributor

@killagu killagu commented Feb 24, 2018

cp.exec decide to use _stdout(_stdout is string) or
Buffer.concat(_stdout)(_stdout is buffer array) by options.encoding.
but std(out|err) encoding can be changed. If encoding is changed to
not null, _stdout will become string, and Buffer.concat(_stdout)
will throw TypeError. This patch will fix it, use
options.encoding and std(out|err)._readableState.encoding.

Fixes: #18969

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines
Affected core subsystem(s)

child_process

@nodejs-github-bot nodejs-github-bot added the child_process Issues and PRs related to the child_process subsystem. label Feb 24, 2018
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about using process.{stdout,stderr}.write()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

process.std.write is ok. But in other test-child-process tests use the console, like encoding,env.

@hstarorg
Copy link

hstarorg commented Feb 25, 2018

The stdoutLen will be affect when encoding changed.
https://github.com/killagu/node/blob/c40252d80610765e5f6efefc02ea6ba1b95cee17/lib/child_process.js#L336-L345
The stdoutLen still used old length calculate function when encoding is changed. The case is that string is Chinese.

@killagu
Copy link
Contributor Author

killagu commented Feb 25, 2018

@hstarorg Thanks for the advice, you are right.I have a better solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const readStream = new ReadableStream(); readStream.setEncoding(null); // readStream._readableState.decoder.encoding equals 'utf8' // readStream._readableState.encoding equals null;

_readableState.encoding should be same as this._readableState.decoder.encoding

@BridgeAR
Copy link
Member

BridgeAR commented Apr 9, 2018

@nodejs/streams PTAL

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a test for Readable  alone?

LGTM with that test included.

@BridgeAR
Copy link
Member

Ping @killagu

@BridgeAR
Copy link
Member

@killagu sorry that it took so long for to look at this again, it just slipped through. Would you be so kind and add a test as requested by @mcollina?

@killagu
Copy link
Contributor Author

killagu commented May 2, 2018

@BridgeAR I'm sorry it's taken me so long to get back to you. I'll add the test ASAP.

killagu added 3 commits May 2, 2018 22:15
cp.exec decide to use `_stdout`(_stdout is string) or `Buffer.concat(_stdout)`(_stdout is buffer array) by options.encoding. but std(out|err) encoding can be changed. If encoding is changed to not null, `_stdout` will become string, and `Buffer.concat(_stdout)` will throw TypeError. This patch will fix it, use options.encoding and `std(out|err)._readableState.encoding`. Fixes: nodejs#18969
fix max-buffer fix _stream_readable.setEncoding
@killagu killagu force-pushed the fix-cp-exec-set-encoding branch from daf4cae to 72ebad2 Compare May 2, 2018 14:43
@killagu
Copy link
Contributor Author

killagu commented May 2, 2018

The test has beed added.
@mcollina @BridgeAR

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label May 15, 2018
@BridgeAR
Copy link
Member

@nodejs/child_process PTAL

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 18, 2018
cp.exec decide to use `_stdout`(_stdout is string) or `Buffer.concat(_stdout)`(_stdout is buffer array) by options.encoding. but std(out|err) encoding can be changed. If encoding is changed to not null, `_stdout` will become string, and `Buffer.concat(_stdout)` will throw TypeError. This patch will fix it, use options.encoding and `std(out|err)._readableState.encoding`. PR-URL: nodejs#18976 Fixes: nodejs#18969 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@BridgeAR
Copy link
Member

Landed in 7d81f5d 🎉

@BridgeAR BridgeAR closed this May 18, 2018
MylesBorins pushed a commit that referenced this pull request May 22, 2018
cp.exec decide to use `_stdout`(_stdout is string) or `Buffer.concat(_stdout)`(_stdout is buffer array) by options.encoding. but std(out|err) encoding can be changed. If encoding is changed to not null, `_stdout` will become string, and `Buffer.concat(_stdout)` will throw TypeError. This patch will fix it, use options.encoding and `std(out|err)._readableState.encoding`. PR-URL: #18976 Fixes: #18969 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@addaleax addaleax mentioned this pull request May 22, 2018
@killagu killagu deleted the fix-cp-exec-set-encoding branch July 18, 2018 05:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. child_process Issues and PRs related to the child_process subsystem.

6 participants