mirror of
https://github.com/zebrajr/node.git
synced 2025-12-06 12:20:27 +01:00
child_process: handle undefined/null for fork() args
PR-URL: https://github.com/nodejs/node/pull/22416 Fixes: https://github.com/nodejs/node/issues/20749 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
This commit is contained in:
parent
e8dbd09414
commit
22b41495ea
|
|
@ -65,6 +65,11 @@ exports.fork = function(modulePath /*, args, options*/) {
|
|||
args = arguments[pos++];
|
||||
}
|
||||
|
||||
if (pos < arguments.length &&
|
||||
(arguments[pos] === undefined || arguments[pos] === null)) {
|
||||
pos++;
|
||||
}
|
||||
|
||||
if (pos < arguments.length && arguments[pos] != null) {
|
||||
if (typeof arguments[pos] !== 'object') {
|
||||
throw new TypeError('Incorrect value of args option');
|
||||
|
|
|
|||
1
test/fixtures/child-process-echo-options.js
vendored
Normal file
1
test/fixtures/child-process-echo-options.js
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
process.send({ env: process.env });
|
||||
37
test/parallel/test-child-process-fork-options.js
Normal file
37
test/parallel/test-child-process-fork-options.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
const common = require('../common');
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
// This test ensures that fork should parse options
|
||||
// correctly if args is undefined or null
|
||||
|
||||
const assert = require('assert');
|
||||
const { fork } = require('child_process');
|
||||
|
||||
const expectedEnv = { foo: 'bar' };
|
||||
|
||||
{
|
||||
const cp = fork(fixtures.path('child-process-echo-options.js'), undefined,
|
||||
{ env: Object.assign({}, process.env, expectedEnv) });
|
||||
|
||||
cp.on('message', common.mustCall(({ env }) => {
|
||||
assert.strictEqual(env.foo, expectedEnv.foo);
|
||||
}));
|
||||
|
||||
cp.on('exit', common.mustCall((code) => {
|
||||
assert.strictEqual(code, 0);
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const cp = fork(fixtures.path('child-process-echo-options.js'), null,
|
||||
{ env: Object.assign({}, process.env, expectedEnv) });
|
||||
|
||||
cp.on('message', common.mustCall(({ env }) => {
|
||||
assert.strictEqual(env.foo, expectedEnv.foo);
|
||||
}));
|
||||
|
||||
cp.on('exit', common.mustCall((code) => {
|
||||
assert.strictEqual(code, 0);
|
||||
}));
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user