mirror of https://github.com/lukechilds/node.git
Browse Source
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. PR-URL: https://github.com/nodejs/node/pull/7391 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jackson Tian <shyvo1987@gmail.com> Fixes: https://github.com/nodejs/node/issues/7342 Refs: https://github.com/nodejs/node/issues/1901v4.x
Rich Trott
9 years ago
committed by
Myles Borins
5 changed files with 57 additions and 46 deletions
@ -1,16 +0,0 @@ |
|||||
'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] === 'child') { |
|
||||
console.log(unicode); |
|
||||
} else { |
|
||||
const cmd = `${process.execPath} ${__filename} child`; |
|
||||
|
|
||||
cp.exec(cmd, { maxBuffer: 10 }, common.mustCall((err, stdout, stderr) => { |
|
||||
assert.strictEqual(err.message, 'stdout maxBuffer exceeded'); |
|
||||
})); |
|
||||
} |
|
@ -0,0 +1,31 @@ |
|||||
|
'use strict'; |
||||
|
const common = require('../common'); |
||||
|
const assert = require('assert'); |
||||
|
const cp = require('child_process'); |
||||
|
|
||||
|
function checkFactory(streamName) { |
||||
|
return common.mustCall((err) => { |
||||
|
const message = `${streamName} maxBuffer exceeded`; |
||||
|
assert.strictEqual(err.message, message); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
{ |
||||
|
const cmd = 'echo "hello world"'; |
||||
|
|
||||
|
cp.exec(cmd, { maxBuffer: 5 }, checkFactory('stdout')); |
||||
|
} |
||||
|
|
||||
|
const unicode = '中文测试'; // length = 4, byte length = 12
|
||||
|
|
||||
|
{ |
||||
|
const cmd = `"${process.execPath}" -e "console.log('${unicode}');"`; |
||||
|
|
||||
|
cp.exec(cmd, {maxBuffer: 10}, checkFactory('stdout')); |
||||
|
} |
||||
|
|
||||
|
{ |
||||
|
const cmd = `"${process.execPath}" -e "console.('${unicode}');"`; |
||||
|
|
||||
|
cp.exec(cmd, {maxBuffer: 10}, checkFactory('stderr')); |
||||
|
} |
@ -1,11 +0,0 @@ |
|||||
'use strict'; |
|
||||
require('../common'); |
|
||||
var exec = require('child_process').exec; |
|
||||
var assert = require('assert'); |
|
||||
|
|
||||
var cmd = 'echo "hello world"'; |
|
||||
|
|
||||
exec(cmd, { maxBuffer: 5 }, function(err, stdout, stderr) { |
|
||||
assert.ok(err); |
|
||||
assert.ok(/maxBuffer/.test(err.message)); |
|
||||
}); |
|
Loading…
Reference in new issue