Skip to content

Implementation of setenv in base incorrectly claims empty environment variable not supported on Windows

Relevant code:

-- | @setEnv name value@ sets the specified environment variable to @value@.
--
-- On Windows setting an environment variable to the /empty string/ removes
-- that environment variable from the environment.  For the sake of
-- compatibility we adopt that behavior.  In particular
--
-- @
-- setEnv name \"\"
-- @
--
-- has the same effect as
--
-- @
-- `unsetEnv` name
-- @

This sounds nice and authoritative... and it's also not true.

https://msdn.microsoft.com/en-us/library/windows/desktop/ms686206(v=vs.85).aspx states that only if the pointer is NULL (as opposed to an empty string) is the environment variable deleted.

https://github.com/golang/go/issues/5610 corroborates

So setEnv has been given bogus semantics that don't make sense because empty environment variables ARE supported on Windows.

My suggestion is to just fix this so that setEnv takes empty environment variables. But this would be a BC breaking change.

Trac metadata
Trac field Value
Version 8.0.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component libraries/base
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information