From 2200d92a6ef8c0e42a61620c113be70656e1b5aa Mon Sep 17 00:00:00 2001 From: cjihrig Date: Fri, 23 Jan 2015 17:18:55 -0500 Subject: [PATCH] child_process: clone spawn options argument spawnSync() modifies the options argument. This commit makes a copy of options before any modifications occur. PR-URL: https://github.com/joyent/node/pull/9159 Reviewed-By: trevnorris - Trevor Norris --- lib/child_process.js | 1 + test/common.js | 11 +++++++++++ test/simple/test-child-process-stdio.js | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/lib/child_process.js b/lib/child_process.js index 8b29132cb4ef..bc1a909fdc45 100644 --- a/lib/child_process.js +++ b/lib/child_process.js @@ -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; diff --git a/test/common.js b/test/common.js index fb81e9f0f01a..3df5c71e4189 100644 --- a/test/common.js +++ b/test/common.js @@ -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; diff --git a/test/simple/test-child-process-stdio.js b/test/simple/test-child-process-stdio.js index 32da15f5f5c8..ec59138db78e 100644 --- a/test/simple/test-child-process-stdio.js +++ b/test/simple/test-child-process-stdio.js @@ -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'});