forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
child_process: preserve argument type
A previous fix for a `maxBuffer` bug resulted in a change to the argument type for the `data` event on `child.stdin` and `child.stdout` when using `child_process.exec()`. This fixes the `maxBuffer` bug in a way that does not have that side effect. Fixes: nodejs#7342 Refs: nodejs#1901
- Loading branch information
Showing
5 changed files
with
51 additions
and
35 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 was deleted.
Oops, something went wrong.
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,27 @@ | ||
'use strict'; | ||
// Refs: https://github.com/nodejs/node/issues/1901 | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const cp = require('child_process'); | ||
const unicode = '中文测试'; // Length = 4, Byte length = 13 | ||
|
||
if (process.argv[2] === 'stdout') { | ||
console.log(unicode); | ||
return; | ||
} | ||
|
||
if (process.argv[2] === 'stderr') { | ||
console.error(unicode); | ||
return; | ||
} | ||
|
||
const cmd = `${process.execPath} ${__filename}`; | ||
const outputs = ['stdout', 'stderr']; | ||
|
||
outputs.forEach((stream) => { | ||
const cb = common.mustCall((err, stdout, stderr) => { | ||
assert.strictEqual(err.message, `${stream} maxBuffer exceeded`); | ||
}); | ||
|
||
cp.exec(`${cmd} ${stream}`, {maxBuffer: 10}, cb); | ||
}); |
17 changes: 0 additions & 17 deletions
17
test/parallel/test-child-process-exec-stdout-data-string.js
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
test/parallel/test-child-process-exec-stdout-stderr-data-string.js
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,22 @@ | ||
'use strict'; | ||
// Refs: https://github.com/nodejs/node/issues/7342 | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
const exec = require('child_process').exec; | ||
|
||
var stdoutIsString = false; | ||
var stderrIsString = false; | ||
|
||
const command = common.isWindows ? 'dir' : 'ls'; | ||
exec(command).stdout.on('data', (data) => { | ||
stdoutIsString = (typeof data === 'string'); | ||
}); | ||
|
||
exec('fhqwhgads').stderr.on('data', (data) => { | ||
stderrIsString = (typeof data === 'string'); | ||
}); | ||
|
||
process.on('exit', () => { | ||
assert(stdoutIsString); | ||
assert(stderrIsString); | ||
}); |