Skip to content

Commit 7854811

Browse files
committed
child_process: clone spawn options argument
spawnSync() modifies the options argument. This commit makes a copy of options before any modifications occur. Fixes: #576 PR-URL: #579 Reviewed-By: Bert Belder <[email protected]>
1 parent 88aaff9 commit 7854811

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

lib/child_process.js

+1
Original file line numberDiff line numberDiff line change
@@ -931,6 +931,7 @@ function normalizeSpawnArguments(file /*, args, options*/) {
931931
else if (!util.isObject(options))
932932
throw new TypeError('options argument must be an object');
933933

934+
options = util._extend({}, options);
934935
args.unshift(file);
935936

936937
var env = options.env || process.env;

test/common.js

+11
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,17 @@ exports.spawnCat = function(options) {
9797
};
9898

9999

100+
exports.spawnSyncCat = function(options) {
101+
var spawnSync = require('child_process').spawnSync;
102+
103+
if (process.platform === 'win32') {
104+
return spawnSync('more', [], options);
105+
} else {
106+
return spawnSync('cat', [], options);
107+
}
108+
};
109+
110+
100111
exports.spawnPwd = function(options) {
101112
var spawn = require('child_process').spawn;
102113

test/parallel/test-child-process-stdio.js

+4
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,7 @@ child = common.spawnPwd(options);
1313

1414
assert.equal(child.stdout, null);
1515
assert.equal(child.stderr, null);
16+
17+
options = {stdio: 'ignore'};
18+
child = common.spawnSyncCat(options);
19+
assert.deepEqual(options, {stdio: 'ignore'});

0 commit comments

Comments
 (0)