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: regression in os.Expand treatment of '${}' #26135

Closed
iand opened this issue Jun 29, 2018 · 6 comments
Closed

os: regression in os.Expand treatment of '${}' #26135

iand opened this issue Jun 29, 2018 · 6 comments

Comments

@iand
Copy link
Contributor

@iand iand commented Jun 29, 2018

Please answer these questions before submitting your issue. Thanks!

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

tip

Does this issue reproduce with the latest release?

yes

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/iand/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/iand"
GORACE=""
GOROOT="/opt/go"
GOTMPDIR=""
GOTOOLDIR="/opt/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build689803627=/tmp/go-build -gno-record-gcc-switches"

What did you do?

package main

import (
	"fmt"
	"os"
)

func main() {
	fmt.Printf("%q", substituteEnv("${}"))
}

func substituteEnv(s string) string {
	return os.Expand(s, func(key string) string {
		if val, ok := os.LookupEnv(key); ok {
			return val
		}
		return key
	})
}

What did you expect to see?

An empty string printed. The Go 1.10 behaviour is that os.Expand returns an empty string.

Can be see on playground which is currently running Go 1.10.2

What did you see instead?

The $ is printed without the braces.

The CL that introduced the new behaviour: 7bf631e derived from #24345

@agnivade
Copy link
Contributor

@agnivade agnivade commented Jun 29, 2018

Well, that was intentional. Not sure if something can be done about it. /cc @ianlancetaylor

@agnivade agnivade added this to the Go1.11 milestone Jun 29, 2018
@iand
Copy link
Contributor Author

@iand iand commented Jun 29, 2018

I think I'd expect it to either output ${} or an empty string. $ on its own seems wrong.

@mvdan
Copy link
Member

@mvdan mvdan commented Jun 29, 2018

None of the added test cases in that CL test for ${}, nor do they make any characters disappear, so I think this was a mistake. Will look into a fix.

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 29, 2018

Change https://golang.org/cl/121636 mentions this issue: os: treat "${}" in Expand like in Go 1.10

@agnivade
Copy link
Contributor

@agnivade agnivade commented Jun 29, 2018

Thanks @mvdan. I was afraid we would be adding checks for more edge cases. But I guess it's better not to break existing behavior.

@mvdan
Copy link
Member

@mvdan mvdan commented Jun 29, 2018

@agnivade indeed. I'm more concerned about consistency than existing behavior, but both are important. See my comment on the CL for an alternative approach that doesn't keep existing behavior.

@gopherbot gopherbot closed this in a94a390 Jun 29, 2018
@golang golang locked and limited conversation to collaborators Jun 29, 2019
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
4 participants
You can’t perform that action at this time.