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

Commit

Permalink
child_process: check fork args is an array
Browse files Browse the repository at this point in the history
Optional fork args should be type-checked with same behaviour as the
equivalent argument to spawn.

PR-URL: #8454
Reviewed-by: Trevor Norris <[email protected]>
  • Loading branch information
sam-github authored and trevnorris committed Nov 19, 2014
1 parent e17c5a7 commit 70dafa7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,8 @@ exports.fork = function(modulePath /*, args, options*/) {
if (Array.isArray(arguments[1])) {
args = arguments[1];
options = util._extend({}, arguments[2]);
} else if (arguments[1] && typeof arguments[1] !== 'object') {
throw new TypeError('Incorrect value of args option');
} else {
args = [];
options = util._extend({}, arguments[1]);
Expand Down
11 changes: 11 additions & 0 deletions test/simple/test-child-process-spawn-typeerror.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
var assert = require('assert');
var child_process = require('child_process');
var spawn = child_process.spawn;
var fork = child_process.fork;
var execFile = child_process.execFile;
var cmd = (process.platform === 'win32') ? 'dir' : 'ls';
var empty = require('../common').fixturesDir + '/empty.js';


// verify that args argument must be an array
Expand All @@ -45,3 +47,12 @@ assert.throws(function() {
assert.doesNotThrow(function() {
execFile(cmd, {});
});

// verify that fork has same argument parsing behaviour as spawn
assert.throws(function() {
fork(empty, 'this is not an array');
}, TypeError);

assert.doesNotThrow(function() {
execFile(empty, {});
});

0 comments on commit 70dafa7

Please sign in to comment.