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:
parent
3f83c83bd6
commit
599aa6dd6d
@ -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
|
||||
}
|
||||
|
||||
|
20
src/cmd/go/testdata/script/mod_init_path.txt
vendored
Normal file
20
src/cmd/go/testdata/script/mod_init_path.txt
vendored
Normal 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() {}
|
Loading…
Reference in New Issue
Block a user