Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d1ac802

Browse filesBrowse files
shobhitchittoraMylesBorins
authored andcommitted
child_process: handle undefined/null for fork() args
PR-URL: #22416 Fixes: #20749 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: Matheus Marchini <mat@mmarchini.me>
1 parent b89297b commit d1ac802
Copy full SHA for d1ac802

File tree

Expand file treeCollapse file tree

3 files changed

+43
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+43
-0
lines changed
Open diff view settings
Collapse file

‎lib/child_process.js‎

Copy file name to clipboardExpand all lines: lib/child_process.js
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ exports.fork = function fork(modulePath /* , args, options */) {
6969
args = arguments[pos++];
7070
}
7171

72+
if (pos < arguments.length &&
73+
(arguments[pos] === undefined || arguments[pos] === null)) {
74+
pos++;
75+
}
76+
7277
if (pos < arguments.length && arguments[pos] != null) {
7378
if (typeof arguments[pos] !== 'object') {
7479
throw new ERR_INVALID_ARG_VALUE(`arguments[${pos}]`, arguments[pos]);
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
process.send({ env: process.env });
Collapse file
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
'use strict';
2+
const common = require('../common');
3+
const fixtures = require('../common/fixtures');
4+
5+
// This test ensures that fork should parse options
6+
// correctly if args is undefined or null
7+
8+
const assert = require('assert');
9+
const { fork } = require('child_process');
10+
11+
const expectedEnv = { foo: 'bar' };
12+
13+
{
14+
const cp = fork(fixtures.path('child-process-echo-options.js'), undefined,
15+
{ env: Object.assign({}, process.env, expectedEnv) });
16+
17+
cp.on('message', common.mustCall(({ env }) => {
18+
assert.strictEqual(env.foo, expectedEnv.foo);
19+
}));
20+
21+
cp.on('exit', common.mustCall((code) => {
22+
assert.strictEqual(code, 0);
23+
}));
24+
}
25+
26+
{
27+
const cp = fork(fixtures.path('child-process-echo-options.js'), null,
28+
{ env: Object.assign({}, process.env, expectedEnv) });
29+
30+
cp.on('message', common.mustCall(({ env }) => {
31+
assert.strictEqual(env.foo, expectedEnv.foo);
32+
}));
33+
34+
cp.on('exit', common.mustCall((code) => {
35+
assert.strictEqual(code, 0);
36+
}));
37+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.