Skip to content

Commit ea89ce1

Browse files
author
Bryan C. Mills
committed
cmd/go/internal/modcmd: loosen path validation in "go mod edit"
Replaced modules require only valid import paths, not full module paths that can be fetched with 'go get'. The 'go' command does not in general reject manually-edited go.mod files with these paths, so 'go mod edit' should not reject them either. Fixes #30513 Change-Id: I4f1a5c65937f91d41478f8d218c8018e0c70f320 Reviewed-on: https://go-review.googlesource.com/c/go/+/210343 Run-TryBot: Bryan C. Mills <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Jay Conrod <[email protected]>
1 parent 94ddb2d commit ea89ce1

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/cmd/go/internal/modcmd/edit.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ func runEdit(cmd *base.Command, args []string) {
164164
}
165165

166166
if *editModule != "" {
167-
if err := module.CheckPath(*editModule); err != nil {
167+
if err := module.CheckImportPath(*editModule); err != nil {
168168
base.Fatalf("go mod: invalid -module: %v", err)
169169
}
170170
}
@@ -242,7 +242,7 @@ func parsePathVersion(flag, arg string) (path, version string) {
242242
base.Fatalf("go mod: -%s=%s: need path@version", flag, arg)
243243
}
244244
path, version = strings.TrimSpace(arg[:i]), strings.TrimSpace(arg[i+1:])
245-
if err := module.CheckPath(path); err != nil {
245+
if err := module.CheckImportPath(path); err != nil {
246246
base.Fatalf("go mod: -%s=%s: invalid path: %v", flag, arg, err)
247247
}
248248

@@ -264,7 +264,7 @@ func parsePath(flag, arg string) (path string) {
264264
base.Fatalf("go mod: -%s=%s: need just path, not path@version", flag, arg)
265265
}
266266
path = arg
267-
if err := module.CheckPath(path); err != nil {
267+
if err := module.CheckImportPath(path); err != nil {
268268
base.Fatalf("go mod: -%s=%s: invalid path: %v", flag, arg, err)
269269
}
270270
return path
@@ -278,7 +278,7 @@ func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version
278278
} else {
279279
path, version = strings.TrimSpace(arg[:i]), strings.TrimSpace(arg[i+1:])
280280
}
281-
if err := module.CheckPath(path); err != nil {
281+
if err := module.CheckImportPath(path); err != nil {
282282
if !allowDirPath || !modfile.IsDirectoryPath(path) {
283283
return path, version, fmt.Errorf("invalid %s path: %v", adj, err)
284284
}

src/cmd/go/testdata/script/mod_edit.txt

+14
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ go mod init a.a/b/c
5252
go mod edit -module x.x/y/z
5353
cmpenv go.mod go.mod.edit
5454

55+
# golang.org/issue/30513: don't require go-gettable module paths.
56+
cd $WORK/local
57+
go mod init foo
58+
go mod edit -module local-only [email protected] -replace [email protected]=./other
59+
cmpenv go.mod go.mod.edit
60+
5561
-- x.go --
5662
package x
5763

@@ -159,6 +165,14 @@ exclude x.1 v1.2.0
159165
replace x.1 => y.1/v2 v2.3.6
160166

161167
require x.3 v1.99.0
168+
-- $WORK/local/go.mod.edit --
169+
module local-only
170+
171+
go $goversion
172+
173+
require other-local v1.0.0
174+
175+
replace other-local v1.0.0 => ./other
162176
-- $WORK/go.mod.badfmt --
163177
module x.x/y/z
164178

0 commit comments

Comments
 (0)