1
0
mirror of https://github.com/golang/go synced 2024-11-23 15:30:05 -07:00

cmd/go: validate path in mod init path

When mod init with given module path, validate that module path is a
valid import path.

Note that module.CheckImportPath is used, because module.CheckPath
verifies that module path is something that "go get" can fetch, which is
strictly stronger condition than "a valid module path".

Updates #28389
Fixes #32644

Change-Id: Ia60f218dd7d79186f87be723c28a96d6cb63017e
Reviewed-on: https://go-review.googlesource.com/c/go/+/182560
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
This commit is contained in:
LE Manh Cuong 2019-06-17 11:07:39 +07:00 committed by Bryan C. Mills
parent 3f83c83bd6
commit 599aa6dd6d
2 changed files with 23 additions and 0 deletions

View File

@ -518,6 +518,9 @@ func findAltConfig(dir string) (root, name string) {
func findModulePath(dir string) (string, error) {
if CmdModModule != "" {
// Running go mod init x/y/z; return x/y/z.
if err := module.CheckImportPath(CmdModModule); err != nil {
return "", err
}
return CmdModModule, nil
}

View File

@ -0,0 +1,20 @@
env GO111MODULE=on
! go mod init .
stderr 'malformed import path'
cd x
go mod init example.com/x
cd ../y
go mod init m
-- x/main.go --
package main
func main() {}
-- y/main.go --
package main
func main() {}