Skip to content
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
process: check env->EmitProcessEnvWarning() last
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
commit 5ab98a55bf3976033694a0dd5f4a3d2bbbe47c38
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');