Skip to content

strings.Split an empty string should get a zero length slice, but the return slice's len is 1 #35130

@widon1104

Description

@widon1104

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

$ go version
go version go1.12.5 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
widon@widon-PC:~$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/widon/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/widon/go"
GOPROXY=""
GORACE=""
GOROOT="/home/widon/soft/golang/go"
GOTMPDIR=""
GOTOOLDIR="/home/widon/soft/golang/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build437062802=/tmp/go-build -gno-record-gcc-switches"

What did you do?

2 lines of code:

ret := strings.Split("", " ")
fmt.Println(len(ret), ret)

run this code get:
1 []

What did you expect to see?

strings.Split an empty string should get a zero length slice

What did you see instead?

the return slice's len is 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions