Commit 599aa6dd authored by LE Manh Cuong's avatar LE Manh Cuong Committed by Bryan C. Mills

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: default avatarBryan C. Mills <bcmills@google.com>
parent 3f83c83b
......@@ -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
}
......
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() {}
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