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
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone

Comments

@iand
Copy link
Contributor

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

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

@agnivade agnivade added the NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made. label Jun 29, 2018
@agnivade agnivade added this to the Go1.11 milestone Jun 29, 2018
@iand
Copy link
Contributor Author

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 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

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

@agnivade
Copy link
Contributor

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 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.

@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.
Labels
FrozenDueToAge NeedsDecision Feedback is required from experts, contributors, and/or the community before a change can be made.
Projects
None yet
Development

No branches or pull requests

4 participants