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.

Fixes: #576
PR-URL: #579
Reviewed-By: Bert Belder <[email protected]>
  • Loading branch information
cjihrig committed Jan 26, 2015
1 parent 88aaff9 commit 7854811
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 @@ -931,6 +931,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 @@ -97,6 +97,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/parallel/test-child-process-stdio.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,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 7854811

Please sign in to comment.