]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.16] cmd/go: allow '+' in package import paths in module mode
authorBryan C. Mills <bcmills@google.com>
Tue, 9 Mar 2021 22:23:04 +0000 (17:23 -0500)
committerDavid Chase <drchase@google.com>
Wed, 31 Mar 2021 14:26:53 +0000 (14:26 +0000)
This change upgrades x/mod to pull in the fix from CL 300152.

Updates #44776.
Fixes #44885.

Change-Id: I273f41df2abfff76d91315b7f19fce851c8770d8
Reviewed-on: https://go-review.googlesource.com/c/go/+/300176
Trust: Bryan C. Mills <bcmills@google.com>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: Jay Conrod <jayconrod@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
(cherry picked from commit d33e2192a71c33a604af247161ba1d2c1969e4c7)
Reviewed-on: https://go-review.googlesource.com/c/go/+/300153

src/cmd/go.mod
src/cmd/go.sum
src/cmd/go/testdata/script/mod_invalid_path_plus.txt [new file with mode: 0644]
src/cmd/vendor/golang.org/x/mod/module/module.go
src/cmd/vendor/modules.txt

index 35582f3975f50ee85f575d5c06b1215c8be53733..70b1b0690b38a251fe7ce8a10a97e2b6846d1d86 100644 (file)
@@ -6,7 +6,7 @@ require (
        github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2
        golang.org/x/arch v0.0.0-20201008161808-52c3e6f60cff
        golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897
-       golang.org/x/mod v0.4.2-0.20210302225053-d515b24adc21
+       golang.org/x/mod v0.4.2-0.20210325185522-dbbbf8a3c6ea
        golang.org/x/sys v0.0.0-20201204225414-ed752295db88 // indirect
        golang.org/x/tools v0.0.0-20210107193943-4ed967dd8eff
 )
index 10340d441f1fd0fa980706a1e193638510cef539..edda18b526b147c7858515cc033391644d9ccdbc 100644 (file)
@@ -14,8 +14,8 @@ golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPh
 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897 h1:pLI5jrR7OSLijeIDcmRxNmw2api+jEfxLoykJVice/E=
 golang.org/x/crypto v0.0.0-20201016220609-9e8e0b390897/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
 golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
-golang.org/x/mod v0.4.2-0.20210302225053-d515b24adc21 h1:FnWKa8BJXkVQ+16E52jkfBOJPx2cG8y/6X376nOgSM4=
-golang.org/x/mod v0.4.2-0.20210302225053-d515b24adc21/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
+golang.org/x/mod v0.4.2-0.20210325185522-dbbbf8a3c6ea h1:zAn46O7Vmm6KdLXx+635hPZSArrt/wNctv4Ab70Jw3k=
+golang.org/x/mod v0.4.2-0.20210325185522-dbbbf8a3c6ea/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
 golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
 golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
 golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
diff --git a/src/cmd/go/testdata/script/mod_invalid_path_plus.txt b/src/cmd/go/testdata/script/mod_invalid_path_plus.txt
new file mode 100644 (file)
index 0000000..2f2488f
--- /dev/null
@@ -0,0 +1,32 @@
+# https://golang.org/issue/44776
+# The '+' character should be disallowed in module paths, but allowed in package
+# paths within valid modules.
+
+go get -d example.net/cmd
+go list example.net/cmd/x++
+
+! go list -versions -m 'example.net/bad++'
+stderr '^go list -m: module example.net/bad\+\+: malformed module path "example.net/bad\+\+": invalid char ''\+''$'
+
+# TODO(bcmills): 'go get -d example.net/cmd/x++' should also work, but currently
+# it does not. This might be fixed by https://golang.org/cl/297891.
+! go get -d example.net/cmd/x++
+stderr '^go get: malformed module path "example.net/cmd/x\+\+": invalid char ''\+''$'
+
+-- go.mod --
+module example.com/m
+
+go 1.16
+
+replace (
+       example.net/cmd => ./cmd
+)
+
+-- cmd/go.mod --
+module example.net/cmd
+
+go 1.16
+-- cmd/x++/main.go --
+package main
+
+func main() {}
index 272baeef176d84caa42da02f8aba72e50769ef8d..0e03014837cc8bb21df5ed1b30da70ef86d30bd9 100644 (file)
@@ -224,12 +224,16 @@ func firstPathOK(r rune) bool {
                'a' <= r && r <= 'z'
 }
 
-// pathOK reports whether r can appear in an import path element.
+// modPathOK reports whether r can appear in a module path element.
 // Paths can be ASCII letters, ASCII digits, and limited ASCII punctuation: - . _ and ~.
-// This matches what "go get" has historically recognized in import paths.
+//
+// This matches what "go get" has historically recognized in import paths,
+// and avoids confusing sequences like '%20' or '+' that would change meaning
+// if used in a URL.
+//
 // TODO(rsc): We would like to allow Unicode letters, but that requires additional
 // care in the safe encoding (see "escaped paths" above).
-func pathOK(r rune) bool {
+func modPathOK(r rune) bool {
        if r < utf8.RuneSelf {
                return r == '-' || r == '.' || r == '_' || r == '~' ||
                        '0' <= r && r <= '9' ||
@@ -239,6 +243,17 @@ func pathOK(r rune) bool {
        return false
 }
 
+// modPathOK reports whether r can appear in a package import path element.
+//
+// Import paths are intermediate between module paths and file paths: we allow
+// disallow characters that would be confusing or ambiguous as arguments to
+// 'go get' (such as '@' and ' ' ), but allow certain characters that are
+// otherwise-unambiguous on the command line and historically used for some
+// binary names (such as '++' as a suffix for compiler binaries and wrappers).
+func importPathOK(r rune) bool {
+       return modPathOK(r) || r == '+'
+}
+
 // fileNameOK reports whether r can appear in a file name.
 // For now we allow all Unicode letters but otherwise limit to pathOK plus a few more punctuation characters.
 // If we expand the set of allowed characters here, we have to
@@ -394,12 +409,19 @@ func checkElem(elem string, kind pathKind) error {
        if elem[len(elem)-1] == '.' {
                return fmt.Errorf("trailing dot in path element")
        }
-       charOK := pathOK
-       if kind == filePath {
-               charOK = fileNameOK
-       }
        for _, r := range elem {
-               if !charOK(r) {
+               ok := false
+               switch kind {
+               case modulePath:
+                       ok = modPathOK(r)
+               case importPath:
+                       ok = importPathOK(r)
+               case filePath:
+                       ok = fileNameOK(r)
+               default:
+                       panic(fmt.Sprintf("internal error: invalid kind %v", kind))
+               }
+               if !ok {
                        return fmt.Errorf("invalid char %q", r)
                }
        }
index 10842768a8840e2ee89b4d0e7cf4b3dc136ee3d1..ae2c0a00cce90bcf8b8979b20600db080ec91a90 100644 (file)
@@ -28,7 +28,7 @@ golang.org/x/arch/x86/x86asm
 golang.org/x/crypto/ed25519
 golang.org/x/crypto/ed25519/internal/edwards25519
 golang.org/x/crypto/ssh/terminal
-# golang.org/x/mod v0.4.2-0.20210302225053-d515b24adc21
+# golang.org/x/mod v0.4.2-0.20210325185522-dbbbf8a3c6ea
 ## explicit
 golang.org/x/mod/internal/lazyregexp
 golang.org/x/mod/modfile