]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: ignore '@' when cleaning local and absolute file path args
authorJay Conrod <jayconrod@google.com>
Wed, 23 Oct 2019 17:47:36 +0000 (13:47 -0400)
committerJay Conrod <jayconrod@google.com>
Wed, 23 Oct 2019 18:41:38 +0000 (18:41 +0000)
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: Bryan C. Mills <bcmills@google.com>
src/cmd/go/internal/search/search.go
src/cmd/go/script_test.go
src/cmd/go/testdata/script/mod_fs_patterns.txt

index 33ab4ae36eb5602fb835afd9dd2a8a5b633e963b..ef3835bfa4e05939770ba18ed486dd8c28378cc8 100644 (file)
@@ -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]
index 31e527fd4085c7e5dbd670c93b2b18419035dcdb..362a10fa86fe1e59d8868ffc3b4e17b1e327762b 100644 (file)
@@ -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)
 }
 
index fd7de13002410325e21975c4cc3e32051309709b..4911fbb613849ad3ed283b8d7e50eb358d0e0e71 100644 (file)
@@ -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