diff --git a/src/node_env_var.cc b/src/node_env_var.cc index 9df5ca82202..8fed12367f8 100644 --- a/src/node_env_var.cc +++ b/src/node_env_var.cc @@ -121,7 +121,7 @@ void RealEnvStore::Set(Isolate* isolate, node::Utf8Value val(isolate, value); #ifdef _WIN32 - if (key[0] == L'=') return; + if (key.length() > 0 && key[0] == L'=') return; #endif uv_os_setenv(*key, *val); DateTimeConfigurationChangeNotification(isolate, key); diff --git a/test/parallel/test-process-env.js b/test/parallel/test-process-env.js index 0e06306634c..4ece826e8b9 100644 --- a/test/parallel/test-process-env.js +++ b/test/parallel/test-process-env.js @@ -106,3 +106,11 @@ if (common.isWindows) { const keys = Object.keys(process.env); assert.ok(keys.length > 0); } + +// Setting environment variables on Windows with empty names should not cause +// an assertion failure. +// https://github.com/nodejs/node/issues/32920 +{ + process.env[''] = ''; + assert.strictEqual(process.env[''], undefined); +}