Skip to content

Commit

Permalink
child_process: clone spawn options argument
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
cjihrig authored and jasnell committed Aug 27, 2015
1 parent 0363cf4 commit b5a0abc
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -967,6 +967,7 @@ function normalizeSpawnArguments(file /*, args, options*/) {
else if (!util.isObject(options))
throw new TypeError('options argument must be an object');

options = util._extend({}, options);
args.unshift(file);

var env = options.env || process.env;
Expand Down
11 changes: 11 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ exports.spawnCat = function(options) {
};


exports.spawnSyncCat = function(options) {
var spawnSync = require('child_process').spawnSync;

if (process.platform === 'win32') {
return spawnSync('more', [], options);
} else {
return spawnSync('cat', [], options);
}
};


exports.spawnPwd = function(options) {
var spawn = require('child_process').spawn;

Expand Down
4 changes: 4 additions & 0 deletions test/simple/test-child-process-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,7 @@ child = common.spawnPwd(options);

assert.equal(child.stdout, null);
assert.equal(child.stderr, null);

options = {stdio: 'ignore'};
child = common.spawnSyncCat(options);
assert.deepEqual(options, {stdio: 'ignore'});

0 comments on commit b5a0abc

Please sign in to comment.