From: Jay Conrod Date: Wed, 23 Oct 2019 17:47:36 +0000 (-0400) Subject: cmd/go: ignore '@' when cleaning local and absolute file path args X-Git-Tag: go1.14beta1~610 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=7833302a6258a65bc17526b54347601df5ff1c5e;p=gostls13.git cmd/go: ignore '@' when cleaning local and absolute file path args Since CL 194600, search.CleanPaths preserves characters after '@' in each argument. This was done so that paths could be cleaned while version queries were preserved. However, local and absolute file paths may contain '@' characters. With this change, '@' is treated as a normal character by search.CleanPaths in local and absolute paths. Fixes #35115 Change-Id: Ia7d37e0a2737442d4f1796cc2fc3a59237a8ddfe Reviewed-on: https://go-review.googlesource.com/c/go/+/202761 Run-TryBot: Jay Conrod TryBot-Result: Gobot Gobot Reviewed-by: Bryan C. Mills --- diff --git a/src/cmd/go/internal/search/search.go b/src/cmd/go/internal/search/search.go index 33ab4ae36e..ef3835bfa4 100644 --- a/src/cmd/go/internal/search/search.go +++ b/src/cmd/go/internal/search/search.go @@ -361,10 +361,10 @@ func ImportPathsQuiet(patterns []string) []*Match { return out } -// CleanPatterns returns the patterns to use for the given -// command line. It canonicalizes the patterns but does not -// evaluate any matches. It preserves text after '@' for commands -// that accept versions. +// CleanPatterns returns the patterns to use for the given command line. It +// canonicalizes the patterns but does not evaluate any matches. For patterns +// that are not local or absolute paths, it preserves text after '@' to avoid +// modifying version queries. func CleanPatterns(patterns []string) []string { if len(patterns) == 0 { return []string{"."} @@ -372,7 +372,9 @@ func CleanPatterns(patterns []string) []string { var out []string for _, a := range patterns { var p, v string - if i := strings.IndexByte(a, '@'); i < 0 { + if build.IsLocalImport(a) || filepath.IsAbs(a) { + p = a + } else if i := strings.IndexByte(a, '@'); i < 0 { p = a } else { p = a[:i] diff --git a/src/cmd/go/script_test.go b/src/cmd/go/script_test.go index 31e527fd40..362a10fa86 100644 --- a/src/cmd/go/script_test.go +++ b/src/cmd/go/script_test.go @@ -117,6 +117,7 @@ func (ts *testScript) setup() { "GOSUMDB=" + testSumDBVerifierKey, "GONOPROXY=", "GONOSUMDB=", + "PWD=" + ts.cd, tempEnvName() + "=" + filepath.Join(ts.workdir, "tmp"), "devnull=" + os.DevNull, "goversion=" + goVersion(ts), @@ -414,6 +415,7 @@ func (ts *testScript) cmdCd(neg bool, args []string) { ts.fatalf("%s is not a directory", dir) } ts.cd = dir + ts.envMap["PWD"] = dir fmt.Fprintf(&ts.log, "%s\n", ts.cd) } diff --git a/src/cmd/go/testdata/script/mod_fs_patterns.txt b/src/cmd/go/testdata/script/mod_fs_patterns.txt index fd7de13002..4911fbb613 100644 --- a/src/cmd/go/testdata/script/mod_fs_patterns.txt +++ b/src/cmd/go/testdata/script/mod_fs_patterns.txt @@ -1,7 +1,6 @@ -# File system pattern searches should skip sub-modules and vendor directories. - env GO111MODULE=on +# File system pattern searches should skip sub-modules and vendor directories. cd x # all packages @@ -40,6 +39,24 @@ stderr '^can.t load package: package ./nonexist: cannot find package "." in:\n\t ! stderr 'import lookup disabled' stderr 'can.t load package: package ./go.mod: cannot find package' + +# File system paths and patterns should allow the '@' character. +cd ../@at +go list $PWD +stdout '^at$' +go list $PWD/... +stdout '^at$' + +# The '@' character is not allowed in directory paths that are part of +# a package path. +cd ../badat/bad@ +! go list . +stderr 'directory . outside available modules' +! go list $PWD +stderr 'directory . outside available modules' +! go list $PWD/... +stderr 'directory . outside available modules' + -- x/go.mod -- module m @@ -64,3 +81,17 @@ package z -- x/y/z/w/w.go -- package w + +-- @at/go.mod -- +module at + +go 1.14 +-- @at/at.go -- +package at + +-- badat/go.mod -- +module badat + +go 1.14 +-- badat/bad@/bad.go -- +package bad