Skip to content

Commit 599aa6d

Browse files
cuonglmBryan C. Mills
authored and
Bryan C. Mills
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Bryan C. Mills <[email protected]>
1 parent 3f83c83 commit 599aa6d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

src/cmd/go/internal/modload/init.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,9 @@ func findAltConfig(dir string) (root, name string) {
518518
func findModulePath(dir string) (string, error) {
519519
if CmdModModule != "" {
520520
// Running go mod init x/y/z; return x/y/z.
521+
if err := module.CheckImportPath(CmdModModule); err != nil {
522+
return "", err
523+
}
521524
return CmdModModule, nil
522525
}
523526

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
env GO111MODULE=on
2+
3+
! go mod init .
4+
stderr 'malformed import path'
5+
6+
cd x
7+
go mod init example.com/x
8+
9+
cd ../y
10+
go mod init m
11+
12+
-- x/main.go --
13+
package main
14+
15+
func main() {}
16+
17+
-- y/main.go --
18+
package main
19+
20+
func main() {}

0 commit comments

Comments
 (0)