Skip to content

Commit 92dd899

Browse files
bcoeaddaleax
authored andcommitted
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. PR-URL: #25575 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent 5684da5 commit 92dd899

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/node_env_var.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ static void EnvSetter(Local<Name> property,
7272
Local<Value> value,
7373
const PropertyCallbackInfo<Value>& info) {
7474
Environment* env = Environment::GetCurrent(info);
75-
if (env->options()->pending_deprecation && env->EmitProcessEnvWarning() &&
76-
!value->IsString() && !value->IsNumber() && !value->IsBoolean()) {
75+
// calling env->EmitProcessEnvWarning() sets a variable indicating that
76+
// warnings have been emitted. It should be called last after other
77+
// conditions leading to a warning have been met.
78+
if (env->options()->pending_deprecation && !value->IsString() &&
79+
!value->IsNumber() && !value->IsBoolean() &&
80+
env->EmitProcessEnvWarning()) {
7781
if (ProcessEmitDeprecationWarning(
7882
env,
7983
"Assigning any value other than a string, number, or boolean to a "

test/parallel/test-process-env-deprecation.js

+4
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,9 @@ common.expectWarning(
1212
'DEP0104'
1313
);
1414

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

0 commit comments

Comments
 (0)