Commit 7833302a authored by Jay Conrod's avatar Jay Conrod

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 <jayconrod@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
parent 67fb5530
......@@ -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]
......
......@@ -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)
}
......
# 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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment