-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: fix exec set stdout.setEncoding
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>
- Loading branch information
1 parent
aaf1df5
commit 4710349
Showing
5 changed files
with
82 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const stdoutData = 'foo'; | ||
const stderrData = 'bar'; | ||
const expectedStdout = `${stdoutData}\n`; | ||
const expectedStderr = `${stderrData}\n`; | ||
|
||
if (process.argv[2] === 'child') { | ||
// The following console calls are part of the test. | ||
console.log(stdoutData); | ||
console.error(stderrData); | ||
} else { | ||
const cmd = `"${process.execPath}" "${__filename}" child`; | ||
const child = cp.exec(cmd, common.mustCall((err, stdout, stderr) => { | ||
assert.ifError(err); | ||
assert.strictEqual(stdout, expectedStdout); | ||
assert.strictEqual(stderr, expectedStderr); | ||
})); | ||
child.stdout.setEncoding('utf-8'); | ||
child.stderr.setEncoding('utf-8'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
const assert = require('assert'); | ||
const { Readable } = require('stream'); | ||
|
||
|
||
{ | ||
const readable = new Readable({ encoding: 'hex' }); | ||
assert.strictEqual(readable._readableState.encoding, 'hex'); | ||
|
||
readable.setEncoding(null); | ||
|
||
assert.strictEqual(readable._readableState.encoding, 'utf8'); | ||
} |