Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: Clearenv sets variables to "" rather than deleting them on Windows #17902

Closed
jszwedko opened this issue Nov 13, 2016 · 2 comments
Closed
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Milestone

Comments

@jszwedko
Copy link
Contributor

It appears that, on Windows, os.Clearenv sets all variables to "" rather than actually unsetting them (as it does on Linux and Unix based other platforms).

I can submit a patch for this, but wanted to clarify if it was expected behavior.

What version of Go are you using (go version)?

go version go1.7.3 windows/386

What operating system and processor architecture are you using (go env)?

windows/386

What did you do?

package main

import (
        "fmt"
        "os"
)

func main() {
        os.Setenv("FOO", "bar")
        v, ok := os.LookupEnv("FOO")
        fmt.Printf("%q %q\n", v, ok)

        os.Clearenv()
        v, ok = os.LookupEnv("FOO")
        fmt.Printf("%q %q\n", v, ok)

        os.Unsetenv("FOO")
        v, ok = os.LookupEnv("FOO")
        fmt.Printf("%q %q\n", v, ok)
}

What did you expect to see?

"bar" %!q(bool=true)
"" %!q(bool=false)
"" %!q(bool=false)

What did you see instead?

"bar" %!q(bool=true)
"" %!q(bool=true)
"" %!q(bool=false)

On linux/amd64:

"bar" %!q(bool=true)
"" %!q(bool=false)
"" %!q(bool=false)
@bradfitz
Copy link
Contributor

Not intentional. Feel free to send a fix.

The Go 1.8 dev cycle is closed for the release freeze, though, so it might not make it until Go 1.9.

@bradfitz bradfitz changed the title os.Clearenv sets variables to "" rather than deleting them on Windows os: Clearenv sets variables to "" rather than deleting them on Windows Nov 13, 2016
@bradfitz bradfitz added this to the Go1.9 milestone Nov 13, 2016
@bradfitz bradfitz added the NeedsFix The path to resolution is known, but the work has not been done. label Nov 13, 2016
@gopherbot
Copy link

CL https://golang.org/cl/33168 mentions this issue.

@golang golang locked and limited conversation to collaborators Nov 14, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Projects
None yet
Development

No branches or pull requests

3 participants