Skip to content

Commit

Permalink
process: check env->EmitProcessEnvWarning() last
Browse files Browse the repository at this point in the history
Calling env->EmitProcessEnvWarning() prevents additional warnings
from being set it should therefore be called only if a warning will
emit.
  • Loading branch information
bcoe committed Jan 21, 2019
1 parent 8b2e861 commit 5ab98a5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/node_env_var.cc
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ static void EnvSetter(Local<Name> property,
Local<Value> value,
const PropertyCallbackInfo<Value>& info) {
Environment* env = Environment::GetCurrent(info);
if (env->options()->pending_deprecation && env->EmitProcessEnvWarning() &&
!value->IsString() && !value->IsNumber() && !value->IsBoolean()) {
// calling env->EmitProcessEnvWarning() sets a variable indicating that
// warnings have been emitted. It should be called last after other
// conditions leading to a warning have been met.
if (env->options()->pending_deprecation && !value->IsString() &&
!value->IsNumber() && !value->IsBoolean() &&
env->EmitProcessEnvWarning()) {
if (ProcessEmitDeprecationWarning(
env,
"Assigning any value other than a string, number, or boolean to a "
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-process-env-deprecation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,9 @@ common.expectWarning(
'DEP0104'
);

// Make sure setting a valid environment variable doesn't
// result in warning being suppressed, see:
// https://github.com/nodejs/node/pull/25157
process.env.FOO = 'apple';
process.env.ABC = undefined;
assert.strictEqual(process.env.ABC, 'undefined');

0 comments on commit 5ab98a5

Please sign in to comment.