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

filepath: Split issue on Windows #33225

Blackmage89 opened this issue Jul 22, 2019 · 1 comment


Copy link

commented Jul 22, 2019

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

$ go version
go version go1.11.4 windows/amd64

Does this issue reproduce with the latest release?

I don't have a working installation of it at the moment.

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

go env Output
$ go env

set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\vittorio.parrella\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=c:\GOPATH\trunk\ETS2
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set GOMOD=
set CGO_CFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\VITTOR~1.PAR\AppData\Local\Temp\2\go-build213636594=/tmp/go-build -gno-record-gcc-switches

What did you do?

import (

func main() {
	dir,file := filepath.Split(`C:\test\test.jpg`)
	fmt.Println("path: ", dir, " - file: ", file)

        // this is the problematic scenario
        // seems that if there is more than separator at the start, the split does not work
	dir,file = filepath.Split(`\\test/test.jpg`)
	fmt.Println("path: ", dir, " - file: ", file)
	dir,file = filepath.Split(`\test/test.jpg`)
	fmt.Println("path: ", dir, " - file: ", file)

	dir,file = filepath.Split(`//test/test.jpg`)
	fmt.Println("path: ", dir, " - file: ", file)

       // in fact, using path.Clean eliminates the problem
	dir,file = filepath.Split(path.Clean(`//test/test.jpg`))
	fmt.Println("path: ", dir, " - file: ", file)

What did you expect to see?

path:  C:\test\  - file:  test.jpg
path:  \\test/  - file:  test.jpg
path:  \test/  - file:  test.jpg
path:  ////test/  - file:  test.jpg
path:  /test/  - file:  test.jpg

What did you see instead?

path:  C:\test\  - file:  test.jpg
path:  \\test/test.jpg  - file:  
path:  \test/  - file:  test.jpg
path:  //test/  - file:  test.jpg
path:  /test/  - file:  test.jpg

On linux it seems that the issue does not manifest, the output is as expected (minus the absolute windows path which is ok):


This comment has been minimized.

Copy link

commented Jul 22, 2019

Just checked again and i wrongly said that path.Clean works around the issue on the last scenario, it does not using "\\test/test.jpg", the result is the same as without path.Clean

@ALTree ALTree changed the title filepath.Split issue on Windows filepath: Split issue on Windows Jul 24, 2019

@ALTree ALTree added this to the Go1.14 milestone Jul 24, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.