x/tools/go/packages/packagestest: fix GOPROXY file URLs for Windows
On Windows, file URLs should look like file:///C:/foo/bar instead of
file://C:/foo/bar. In the latter case, the "C:" is parsed as the host.
Updates golang/go#31675
Change-Id: I7f75be44dd5d289de3ffdbd20a78130ed03cd233
Reviewed-on: https://go-review.googlesource.com/c/tools/+/173918
Run-TryBot: Jay Conrod <jayconrod@google.com>
Reviewed-by: Ian Cottrell <iancottrell@google.com>
diff --git a/go/packages/packagestest/modules.go b/go/packages/packagestest/modules.go
index 0bcdbf5..1ca961a 100644
--- a/go/packages/packagestest/modules.go
+++ b/go/packages/packagestest/modules.go
@@ -14,6 +14,7 @@
"path"
"path/filepath"
"regexp"
+ "strings"
"golang.org/x/tools/go/packages"
)
@@ -101,6 +102,13 @@
return fmt.Errorf("creating module proxy dir for %v: %v", module, err)
}
}
+ proxyURL := filepath.ToSlash(proxyDir)
+ if !strings.HasPrefix(proxyURL, "/") {
+ // Windows paths will look like C:/foo/bar. In the URL, the C: will be
+ // interpreted as the host, so add a leading /. See golang.org/issue/6027.
+ proxyURL = "/" + proxyURL
+ }
+ proxyURL = "file://" + proxyURL
// Discard the original mod cache dir, which contained the files written
// for us by Export.