Skip to content

Commit b5a0abc

Browse files
cjihrigjasnell
authored andcommitted
child_process: clone spawn options argument
spawnSync() modifies the options argument. This commit makes a copy of options before any modifications occur. PR-URL: nodejs/node-v0.x-archive#9159 Reviewed-By: trevnorris - Trevor Norris <trev.norris@gmail.com>
1 parent 0363cf4 commit b5a0abc

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
@@ -967,6 +967,7 @@ function normalizeSpawnArguments(file /*, args, options*/) {
967967
else if (!util.isObject(options))
968968
throw new TypeError('options argument must be an object');
969969

970+
options = util._extend({}, options);
970971
args.unshift(file);
971972

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

test/common.js

+11
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,17 @@ exports.spawnCat = function(options) {
9999
};
100100

101101

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

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

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

3535
assert.equal(child.stdout, null);
3636
assert.equal(child.stderr, null);
37+
38+
options = {stdio: 'ignore'};
39+
child = common.spawnSyncCat(options);
40+
assert.deepEqual(options, {stdio: 'ignore'});

0 commit comments

Comments
 (0)