Skip to content
This repository has been archived by the owner on Apr 22, 2023. It is now read-only.

Spawn reads env from prototype #713

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,7 @@ ChildProcess.prototype.spawn = function(path, args, options, customFds) {
}

var envPairs = [];
var keys = Object.keys(env);
for (var index = 0, keysLength = keys.length; index < keysLength; index++) {
var key = keys[index];
for (var key in env) {
envPairs.push(key + '=' + env[key]);
}

Expand Down
11 changes: 10 additions & 1 deletion test/simple/test-child-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ var common = require('../common');
var assert = require('assert');

var spawn = require('child_process').spawn;
var child = spawn('/usr/bin/env', [], {env: {'HELLO': 'WORLD'}});

var env = {
'HELLO': 'WORLD'
};
env.__proto__ = {
'FOO': 'BAR'
}

var child = spawn('/usr/bin/env', [], {env: env});

var response = '';

Expand All @@ -15,4 +23,5 @@ child.stdout.addListener('data', function(chunk) {

process.addListener('exit', function() {
assert.ok(response.indexOf('HELLO=WORLD') >= 0);
assert.ok(response.indexOf('FOO=BAR') >= 0);
});