diff --git a/src/node_env_var.cc b/src/node_env_var.cc index 63cba55ab56..60582d7a31c 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -72,8 +72,12 @@ static void EnvSetter(Local property, Local value, const PropertyCallbackInfo& 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 " diff --git a/test/parallel/test-process-env-deprecation.js b/test/parallel/test-process-env-deprecation.js index 68817b320b4..0396d8ff68a 100644 --- a/test/parallel/test-process-env-deprecation.js +++ b/test/parallel/test-process-env-deprecation.js @@ -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');