Skip to content

Commit 99cfd53

Browse files
ChuckLangfordTrott
authored andcommitted
test: test execFile/fork arg validation
Fixes: nodejs#2681 Refs: nodejs#4508 PR-URL: nodejs#7399 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 0548e5d commit 99cfd53

File tree

2 files changed

+34
-5
lines changed

2 files changed

+34
-5
lines changed

lib/child_process.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ exports.fork = function(modulePath /*, args, options*/) {
2323
var options = {};
2424
var args = [];
2525
var pos = 1;
26-
if (Array.isArray(arguments[pos])) {
26+
if (pos < arguments.length && Array.isArray(arguments[pos])) {
2727
args = arguments[pos++];
2828
}
2929

30-
if (arguments[pos] != null) {
30+
if (pos < arguments.length && arguments[pos] != null) {
3131
if (typeof arguments[pos] !== 'object') {
3232
throw new TypeError('Incorrect value of args option');
3333
} else {

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

+32-3
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,36 @@ assert.doesNotThrow(function() { execFile(cmd, a, o, u); });
111111
assert.doesNotThrow(function() { execFile(cmd, n, o, c); });
112112
assert.doesNotThrow(function() { execFile(cmd, a, n, c); });
113113
assert.doesNotThrow(function() { execFile(cmd, a, o, n); });
114+
assert.doesNotThrow(function() { execFile(cmd, u, u, u); });
115+
assert.doesNotThrow(function() { execFile(cmd, u, u, c); });
116+
assert.doesNotThrow(function() { execFile(cmd, u, o, u); });
117+
assert.doesNotThrow(function() { execFile(cmd, a, u, u); });
118+
assert.doesNotThrow(function() { execFile(cmd, n, n, n); });
119+
assert.doesNotThrow(function() { execFile(cmd, n, n, c); });
120+
assert.doesNotThrow(function() { execFile(cmd, n, o, n); });
121+
assert.doesNotThrow(function() { execFile(cmd, a, n, n); });
122+
assert.doesNotThrow(function() { execFile(cmd, a, u); });
123+
assert.doesNotThrow(function() { execFile(cmd, a, n); });
124+
assert.doesNotThrow(function() { execFile(cmd, o, u); });
125+
assert.doesNotThrow(function() { execFile(cmd, o, n); });
126+
assert.doesNotThrow(function() { execFile(cmd, c, u); });
127+
assert.doesNotThrow(function() { execFile(cmd, c, n); });
114128

115129
// string is invalid in arg position (this may seem strange, but is
116130
// consistent across node API, cf. `net.createServer('not options', 'not
117131
// callback')`
118132
assert.throws(function() { execFile(cmd, s, o, c); }, TypeError);
119-
assert.doesNotThrow(function() { execFile(cmd, a, s, c); });
120-
assert.doesNotThrow(function() { execFile(cmd, a, o, s); });
133+
assert.throws(function() { execFile(cmd, a, s, c); }, TypeError);
134+
assert.throws(function() { execFile(cmd, a, o, s); }, TypeError);
135+
assert.throws(function() { execFile(cmd, a, s); }, TypeError);
136+
assert.throws(function() { execFile(cmd, o, s); }, TypeError);
137+
assert.throws(function() { execFile(cmd, u, u, s); }, TypeError);
138+
assert.throws(function() { execFile(cmd, n, n, s); }, TypeError);
139+
assert.throws(function() { execFile(cmd, a, u, s); }, TypeError);
140+
assert.throws(function() { execFile(cmd, a, n, s); }, TypeError);
141+
assert.throws(function() { execFile(cmd, u, o, s); }, TypeError);
142+
assert.throws(function() { execFile(cmd, n, o, s); }, TypeError);
143+
assert.doesNotThrow(function() { execFile(cmd, c, s); });
121144

122145

123146
// verify that fork has same argument parsing behaviour as spawn
@@ -131,6 +154,12 @@ assert.doesNotThrow(function() { fork(empty); });
131154
assert.doesNotThrow(function() { fork(empty, a); });
132155
assert.doesNotThrow(function() { fork(empty, a, o); });
133156
assert.doesNotThrow(function() { fork(empty, o); });
157+
assert.doesNotThrow(function() { fork(empty, u, u); });
158+
assert.doesNotThrow(function() { fork(empty, u, o); });
159+
assert.doesNotThrow(function() { fork(empty, a, u); });
160+
assert.doesNotThrow(function() { fork(empty, n, n); });
161+
assert.doesNotThrow(function() { fork(empty, n, o); });
162+
assert.doesNotThrow(function() { fork(empty, a, n); });
134163

135164
assert.throws(function() { fork(empty, s); }, TypeError);
136-
assert.doesNotThrow(function() { fork(empty, a, s); }, TypeError);
165+
assert.throws(function() { fork(empty, a, s); }, TypeError);

0 commit comments

Comments
 (0)