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

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

jszwedko opened this issue Nov 13, 2016 · 2 comments

Comments

@jszwedko
Copy link
Contributor

@jszwedko jszwedko commented Nov 13, 2016

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

This comment has been minimized.

Copy link
Contributor

@bradfitz bradfitz commented Nov 13, 2016

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 the OS-Windows label Nov 13, 2016
@bradfitz bradfitz added this to the Go1.9 milestone Nov 13, 2016
@bradfitz bradfitz added the NeedsFix label Nov 13, 2016
@gopherbot

This comment has been minimized.

Copy link

@gopherbot gopherbot commented Nov 13, 2016

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

@gopherbot gopherbot closed this in 5f74ce3 Nov 14, 2016
@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.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.