]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/mod/edit: disallow relative tool paths
authorConrad Irwin <conrad.irwin@gmail.com>
Fri, 20 Sep 2024 06:12:48 +0000 (00:12 -0600)
committerMichael Matloob <matloob@golang.org>
Fri, 20 Sep 2024 20:19:15 +0000 (20:19 +0000)
Allowing relative paths in `go.mod` introduced an inconsistency as we do
not allow relative package paths anywhere else.

For golang/go#48429

Change-Id: I5ef88aec4fe35f7e94a0cf6288e94099f3ca7a0e
Reviewed-on: https://go-review.googlesource.com/c/go/+/614555
Reviewed-by: Sam Thanawalla <samthanawalla@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/go/internal/modcmd/edit.go
src/cmd/go/testdata/script/mod_edit.txt

index da84c9ff11077257da345a00e041c236efb7a189..ba3d6ed2997e974ae48716db4fc401433526028b 100644 (file)
@@ -339,25 +339,6 @@ func parsePath(flag, arg string) (path string) {
        return path
 }
 
-// parsePath parses -flag=arg expecting arg to be path to a tool (allows ./)
-func parseToolPath(flag, arg string) (path string) {
-       if strings.Contains(arg, "@") {
-               base.Fatalf("go: -%s=%s: need just path, not path@version", flag, arg)
-       }
-       if arg == "." {
-               return arg
-       }
-       toCheck := arg
-       if strings.HasPrefix(arg, "./") {
-               toCheck = arg[2:]
-       }
-       if err := module.CheckImportPath(toCheck); err != nil {
-               base.Fatalf("go: -%s=%s: invalid path: %v", flag, arg, err)
-       }
-
-       return arg
-}
-
 // parsePathVersionOptional parses path[@version], using adj to
 // describe any errors.
 func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version string, err error) {
@@ -547,7 +528,7 @@ func flagDropRetract(arg string) {
 
 // flagTool implements the -tool flag.
 func flagTool(arg string) {
-       path := parseToolPath("tool", arg)
+       path := parsePath("tool", arg)
        edits = append(edits, func(f *modfile.File) {
                if err := f.AddTool(path); err != nil {
                        base.Fatalf("go: -tool=%s: %v", arg, err)
@@ -557,7 +538,7 @@ func flagTool(arg string) {
 
 // flagDropTool implements the -droptool flag.
 func flagDropTool(arg string) {
-       path := parseToolPath("droptool", arg)
+       path := parsePath("droptool", arg)
        edits = append(edits, func(f *modfile.File) {
                if err := f.DropTool(path); err != nil {
                        base.Fatalf("go: -droptool=%s: %v", arg, err)
index 0b676cf6f966bdf71d41da3ce5ef7d4429a30c92..e52575683327b5a61ce02dddd196f9f4b73c4236 100644 (file)
@@ -102,10 +102,6 @@ cd $WORK/h
 cp go.mod.start go.mod
 go mod edit -tool example.com/tool
 cmpenv go.mod go.mod.edit
-go mod edit -tool ./local
-cmpenv go.mod go.mod.edit2
-go mod edit -droptool ./local
-cmpenv go.mod go.mod.edit
 go mod edit -droptool example.com/tool2
 cmpenv go.mod go.mod.edit
 go mod edit -droptool example.com/tool
@@ -386,12 +382,3 @@ module g
 go 1.24
 
 tool example.com/tool
--- $WORK/h/go.mod.edit2 --
-module g
-
-go 1.24
-
-tool (
-       ./local
-       example.com/tool
-)