From 41d1bf0efc121c451f497ceae8df366622efd821 Mon Sep 17 00:00:00 2001 From: Jay Conrod Date: Thu, 25 Apr 2019 11:59:32 -0400 Subject: [PATCH] cmd/go/internal/modfetch: workaround file URL parsing on Windows Remove the leading slash from GOPROXY file:// URLs. Updates #31675 Change-Id: Id45af2a806afc3c216181c13f6bc73713b925693 Reviewed-on: https://go-review.googlesource.com/c/go/+/173499 Run-TryBot: Jay Conrod TryBot-Result: Gobot Gobot Reviewed-by: Ian Cottrell Reviewed-by: Brad Fitzpatrick --- src/cmd/go/internal/modfetch/proxy.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/cmd/go/internal/modfetch/proxy.go b/src/cmd/go/internal/modfetch/proxy.go index aa1778296f..2d661a0f75 100644 --- a/src/cmd/go/internal/modfetch/proxy.go +++ b/src/cmd/go/internal/modfetch/proxy.go @@ -14,9 +14,11 @@ import ( "os" pathpkg "path" "path/filepath" + "runtime" "strings" "sync" "time" + "unicode" "cmd/go/internal/base" "cmd/go/internal/cfg" @@ -219,6 +221,11 @@ func (p *proxyRepo) getBody(path string) (io.ReadCloser, error) { if err != nil { return nil, err } + if runtime.GOOS == "windows" && len(rawPath) >= 4 && rawPath[0] == '/' && unicode.IsLetter(rune(rawPath[1])) && rawPath[2] == ':' { + // On Windows, file URLs look like "file:///C:/foo/bar". url.Path will + // start with a slash which must be removed. See golang.org/issue/6027. + rawPath = rawPath[1:] + } return os.Open(filepath.FromSlash(rawPath)) } -- 2.50.0