]> Cypherpunks.ru repositories - gostls13.git/commitdiff
cmd/go: handle '@' in local path when running 'go mod edit -replace'
authorQuan Tong <quantonganh@gmail.com>
Wed, 1 Nov 2023 11:08:23 +0000 (18:08 +0700)
committerGopher Robot <gobot@golang.org>
Mon, 6 Nov 2023 18:00:45 +0000 (18:00 +0000)
The existing implementation considers everything after '@' as a version.

Fixes #61500

Change-Id: I72c32529c2726c2b59c089f5ffd6a2e361ef2c65
Reviewed-on: https://go-review.googlesource.com/c/go/+/538916
Auto-Submit: Bryan Mills <bcmills@google.com>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Heschi Kreinick <heschi@google.com>
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 96bd608c01cdf87f0edb1920e5536b20039ebd59..db131b088143bf1cae48723a0b4d75fd27da8adc 100644 (file)
@@ -315,6 +315,9 @@ func parsePath(flag, arg string) (path string) {
 // parsePathVersionOptional parses path[@version], using adj to
 // describe any errors.
 func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version string, err error) {
+       if allowDirPath && modfile.IsDirectoryPath(arg) {
+               return arg, "", nil
+       }
        before, after, found := strings.Cut(arg, "@")
        if !found {
                path = arg
@@ -322,9 +325,7 @@ func parsePathVersionOptional(adj, arg string, allowDirPath bool) (path, version
                path, version = strings.TrimSpace(before), strings.TrimSpace(after)
        }
        if err := module.CheckImportPath(path); err != nil {
-               if !allowDirPath || !modfile.IsDirectoryPath(path) {
-                       return path, version, fmt.Errorf("invalid %s path: %v", adj, err)
-               }
+               return path, version, fmt.Errorf("invalid %s path: %v", adj, err)
        }
        if path != arg && !allowedVersionArg(version) {
                return path, version, fmt.Errorf("invalid %s version: %q", adj, version)
index ebc032a73cf7819171cb48b1137f16d497632d38..2d09b06c6114f92c32ceef60501d7babada71b9e 100644 (file)
@@ -61,6 +61,10 @@ go mod edit -replace=x.1=y.1/v2@v2.3.6
 cmpenv go.mod $WORK/go.mod.edit4
 go mod edit -dropreplace=x.1
 cmpenv go.mod $WORK/go.mod.edit5
+go mod edit -replace=x.1=../y.1/@v2
+cmpenv go.mod $WORK/go.mod.edit6
+! go mod edit -replace=x.1=y.1/@v2
+stderr '^go: -replace=x.1=y.1/@v2: invalid new path: malformed import path "y.1/": trailing slash$'
 
 # go mod edit -fmt
 cp $WORK/go.mod.badfmt go.mod
@@ -218,6 +222,21 @@ retract (
 )
 
 require x.3 v1.99.0
+-- $WORK/go.mod.edit6 --
+module x.x/y/z
+
+go $goversion
+
+exclude x.1 v1.2.0
+
+retract (
+       v1.6.0
+       [v1.3.0, v1.4.0]
+)
+
+require x.3 v1.99.0
+
+replace x.1 => ../y.1/@v2
 -- $WORK/local/go.mod.edit --
 module local-only