diff --git a/src/node_env_var.cc b/src/node_env_var.cc index 5f543a5e76a1f9..8eaf79538a26e7 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] == '=') return; #endif uv_os_setenv(*key, *val); DateTimeConfigurationChangeNotification(isolate, key); @@ -139,7 +139,7 @@ int32_t RealEnvStore::Query(const char* key) const { } #ifdef _WIN32 - if (key[0] == L'=') { + if (key[0] == '=') { return static_cast(v8::ReadOnly) | static_cast(v8::DontDelete) | static_cast(v8::DontEnum); @@ -227,7 +227,7 @@ void MapKVStore::Set(Isolate* isolate, Local key, Local value) { Mutex::ScopedLock lock(mutex_); Utf8Value key_str(isolate, key); Utf8Value value_str(isolate, value); - if (*key_str != nullptr && *value_str != nullptr) { + if (*key_str != nullptr && key_str.length() > 0 && *value_str != nullptr) { map_[std::string(*key_str, key_str.length())] = std::string(*value_str, value_str.length()); } diff --git a/test/parallel/test-process-env.js b/test/parallel/test-process-env.js index 0e06306634c3e2..4ece826e8b938f 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); +}