cmd/internal/quoted: Join does not preserve empty arguments
- Dominant language
- Go
- Stars
- 139k
- Forks
- 19.9k
- PR merge metrics
- PR metrics pending
Description
### Go version
go version go1.25.6 darwin/arm64
### Output of `go env` in your module/workspace:
```shell
AR='ar'
CC='clang'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='1'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='clang++'
GCCGO='gccgo'
GO111MODULE=''
GOARCH='arm64'
GOARM64='v8.0'
GOAUTH='netrc'
GOBIN='/Users/mac/go/bin'
GOCACHE='/Users/mac/Library/Caches/go-build'
GOCACHEPROG=''
GODEBUG=''
GOENV='/Users/mac/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFIPS140='off'
GOFLAGS=''
GOGCCFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMOD='/dev/null'
GOMODCACHE='/Users/mac/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/mac/go'
GOPRIVATE=''
GOPROXY='https://goproxy.cn,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTELEMETRY='local'
GOTELEMETRYDIR='/Users/mac/Library/Application Support/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/darwin_arm64'
GOVCS=''
GOVERSION='go1.25.6'
GOWORK=''
PKG_CONFIG='pkg-config'
```
### What did you do?
`cmd/internal/quoted.Join` documents that it joins a list of arguments into a string that can be parsed with `Split`.
Add the following test in `src/cmd/internal/quoted/empty_test.go` :
```go
func TestJoinEmptyArgument(t *testing.T) {
args := []string{"a", "", "b"}
s, err := Join(args)
if err != nil {
t.Fatal(err)
}
if want := "a '' b"; s != want {
t.Errorf("Join(%#v) = %q; want %q", args, s, want)
}
got, err := Split(s)
if err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(got, args) {
t.Errorf("Split(Join(%#v)) = %#v; want %#v",
args, got, args)
}
}
```
`GO111MODULE=off go test ./src/cmd/internal/quoted \
-run '^TestJoinEmptyArgument$' -v`
### What did you see happen?
### What did you expect to see?
```shell
joined: "a '' b"
split: []string{"a", "", "b"}
```
In other words, successful calls should satisfy:
`Split(Join(args)) == args`
for arguments accepted by `Join`.
Contributor guide
Research direction
Start with cmd/internal/quoted.Join and Split, then add the requested regression test in src/cmd/internal/quoted/empty_test.go. Run GO111MODULE=off go test ./src/cmd/internal/quoted -run '^TestJoinEmptyArgument$' -v. Done means Join accepts ["a", "", "b"] as "a '' b" and Split(Join(args)) returns the original arguments.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 76/100