Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
meta: merge node/master into node-chakracore/master
Browse files Browse the repository at this point in the history
Merge 85739b6 as of 2018-01-15
This commit was automatically generated. For any problems, please contact jackhorton

Reviewed-By: Jack Horton <jahorto@microsoft.com>
  • Loading branch information
chakrabot committed Jan 30, 2018
2 parents e32462b + 85739b6 commit 6464e70
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions doc/api/child_process.md
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ If not given, the default is to inherit the current working directory.
Use `env` to specify environment variables that will be visible to the new
process, the default is [`process.env`][].

`undefined` values in `env` will be ignored.

Example of running `ls -lh /usr`, capturing `stdout`, `stderr`, and the
exit code:

Expand Down
7 changes: 5 additions & 2 deletions lib/child_process.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,11 @@ function normalizeSpawnArguments(file, args, options) {
var env = options.env || process.env;
var envPairs = [];

for (var key in env) {
envPairs.push(`${key}=${env[key]}`);
for (const key of Object.keys(env)) {
const value = env[key];
if (value !== undefined) {
envPairs.push(`${key}=${value}`);
}
}

_convertCustomFds(options);
Expand Down
11 changes: 9 additions & 2 deletions test/parallel/test-child-process-env.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
'use strict';
const common = require('../common');
const assert = require('assert');
const os = require('os');

const spawn = require('child_process').spawn;

const env = {
'HELLO': 'WORLD'
'HELLO': 'WORLD',
'UNDEFINED': undefined,
'NULL': null,
'EMPTY': ''
};
Object.setPrototypeOf(env, {
'FOO': 'BAR'
Expand All @@ -53,5 +57,8 @@ child.stdout.on('data', function(chunk) {

process.on('exit', function() {
assert.ok(response.includes('HELLO=WORLD'));
assert.ok(response.includes('FOO=BAR'));
assert.ok(!response.includes('FOO='));
assert.ok(!response.includes('UNDEFINED=undefined'));
assert.ok(response.includes('NULL=null'));
assert.ok(response.includes(`EMPTY=${os.EOL}`));
});

0 comments on commit 6464e70

Please sign in to comment.