-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
child_process: fix exec set stdout.setEncoding #18976
Conversation
|
||
if (process.argv[2] === 'child') { | ||
// The following console calls are part of the test. | ||
console.log(stdoutData); |
There was a problem hiding this comment.
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()
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The |
@hstarorg Thanks for the advice, you are right.I have a better solution. |
lib/_stream_readable.js
Outdated
@@ -311,7 +311,8 @@ Readable.prototype.setEncoding = function(enc) { | |||
if (!StringDecoder) | |||
StringDecoder = require('string_decoder').StringDecoder; | |||
this._readableState.decoder = new StringDecoder(enc); | |||
this._readableState.encoding = enc; | |||
// if setEncoding(null), decoder.encoding = 'utf8' | |||
this._readableState.encoding = this._readableState.decoder.encoding; |
There was a problem hiding this comment.
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
@nodejs/streams PTAL |
There was a problem hiding this 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.
Ping @killagu |
@BridgeAR I'm sorry it's taken me so long to get back to you. I'll add the test ASAP. |
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
daf4cae
to
72ebad2
Compare
@nodejs/child_process PTAL |
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 <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Landed in 7d81f5d 🎉 |
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 <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
cp.exec decide to use
_stdout
(_stdout is string) orBuffer.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, andBuffer.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), orvcbuild test
(Windows) passesAffected core subsystem(s)
child_process