aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/go/internal/search/search.go
diff options
context:
space:
mode:
authorJay Conrod <jayconrod@google.com>2019-09-10 16:06:12 -0400
committerJay Conrod <jayconrod@google.com>2019-09-11 20:19:25 +0000
commit8875fb97c5cadbc6f02e4ce89efa586023c0a777 (patch)
tree3c96d4ef01698454eaa1826d72d2642882ee9824 /src/cmd/go/internal/search/search.go
parent04867cd89121d9738fb16e8f299a9263a91282eb (diff)
downloadgo-8875fb97c5cadbc6f02e4ce89efa586023c0a777.tar.gz
go-8875fb97c5cadbc6f02e4ce89efa586023c0a777.zip
cmd/go: strip trailing slash from versioned arguments
'go get' accepts arguments of the form path@version, and it passes them through search.CleanPatterns before querying proxies. With this change, CleanPatterns preserves text after '@' and will strip trailing slashes from the patn. Previously, we did not strip trailing slashes when a version was present, which caused proxy base URL validation to fail. Module paths that end with ".go" (for example, github.com/nats-io/nats.go) use trailing slashes to prevent 'go build' and other commands from interpreting packages as source file names, so this caused unnecessary problems for them. Updates #32483 Change-Id: Id3730c52089e52f1cac446617c20132a3021a808 Reviewed-on: https://go-review.googlesource.com/c/go/+/194600 Run-TryBot: Jay Conrod <jayconrod@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Bryan C. Mills <bcmills@google.com>
Diffstat (limited to 'src/cmd/go/internal/search/search.go')
-rw-r--r--src/cmd/go/internal/search/search.go26
1 files changed, 18 insertions, 8 deletions
diff --git a/src/cmd/go/internal/search/search.go b/src/cmd/go/internal/search/search.go
index 0e420c99bd..33ab4ae36e 100644
--- a/src/cmd/go/internal/search/search.go
+++ b/src/cmd/go/internal/search/search.go
@@ -363,30 +363,40 @@ func ImportPathsQuiet(patterns []string) []*Match {
// CleanPatterns returns the patterns to use for the given
// command line. It canonicalizes the patterns but does not
-// evaluate any matches.
+// evaluate any matches. It preserves text after '@' for commands
+// that accept versions.
func CleanPatterns(patterns []string) []string {
if len(patterns) == 0 {
return []string{"."}
}
var out []string
for _, a := range patterns {
+ var p, v string
+ if i := strings.IndexByte(a, '@'); i < 0 {
+ p = a
+ } else {
+ p = a[:i]
+ v = a[i:]
+ }
+
// Arguments are supposed to be import paths, but
// as a courtesy to Windows developers, rewrite \ to /
// in command-line arguments. Handles .\... and so on.
if filepath.Separator == '\\' {
- a = strings.ReplaceAll(a, `\`, `/`)
+ p = strings.ReplaceAll(p, `\`, `/`)
}
// Put argument in canonical form, but preserve leading ./.
- if strings.HasPrefix(a, "./") {
- a = "./" + path.Clean(a)
- if a == "./." {
- a = "."
+ if strings.HasPrefix(p, "./") {
+ p = "./" + path.Clean(p)
+ if p == "./." {
+ p = "."
}
} else {
- a = path.Clean(a)
+ p = path.Clean(p)
}
- out = append(out, a)
+
+ out = append(out, p+v)
}
return out
}