Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

Commit 542ac7f

Browse files
cjihrigtrevnorris
authored andcommitted
child_process: properly support optional args
Currently, a TypeError is incorrectly thrown if the second argument is an object. This commit allows the args argument to be properly omitted. Fixes: #6068 Reviewed-by: Trevor Norris <[email protected]>
1 parent 84952da commit 542ac7f

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/child_process.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ var spawn = exports.spawn = function(file /*, args, options*/) {
711711
if (Array.isArray(arguments[1])) {
712712
args = arguments[1].slice(0);
713713
options = arguments[2];
714-
} else if (arguments[1] && !Array.isArray(arguments[1])) {
714+
} else if (arguments[1] && typeof arguments[1] !== 'object') {
715715
throw new TypeError('Incorrect value of args option');
716716
} else {
717717
args = [];

test/simple/test-child-process-spawn-typeerror.js

+8-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,13 @@
2222
var spawn = require('child_process').spawn,
2323
assert = require('assert'),
2424
windows = (process.platform === 'win32'),
25-
cmd = (windows) ? 'ls' : 'dir',
25+
cmd = (windows) ? 'dir' : 'ls',
26+
invalidcmd = (windows) ? 'ls' : 'dir',
2627
errors = 0;
2728

2829
try {
2930
// Ensure this throws a TypeError
30-
var child = spawn(cmd, 'this is not an array');
31+
var child = spawn(invalidcmd, 'this is not an array');
3132

3233
child.on('error', function (err) {
3334
errors++;
@@ -37,6 +38,11 @@ try {
3738
assert.equal(e instanceof TypeError, true);
3839
}
3940

41+
// verify that args argument is optional
42+
assert.doesNotThrow(function() {
43+
spawn(cmd, {});
44+
});
45+
4046
process.on('exit', function() {
4147
assert.equal(errors, 0);
4248
});

0 commit comments

Comments
 (0)