Browse Source

child_process: check fork args is an array

Optional fork args should be type-checked with same behaviour as the
equivalent argument to spawn.

PR-URL: https://github.com/joyent/node/pull/8454
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
v0.10.34-release
Sam Roberts 10 years ago
committed by Trevor Norris
parent
commit
70dafa7b62
  1. 2
      lib/child_process.js
  2. 11
      test/simple/test-child-process-spawn-typeerror.js

2
lib/child_process.js

@ -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]);

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

@ -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
@ -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, {});
});

Loading…
Cancel
Save