]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/go: replace backslash systematically in path of command
authorConstantin Konstantinidis <constantinkonstantinidis@gmail.com>
Fri, 2 May 2025 07:10:40 +0000 (09:10 +0200)
committerMichael Matloob <matloob@golang.org>
Thu, 8 May 2025 16:19:27 +0000 (09:19 -0700)
Using the same method CleanPatterns harmonizes further accepted format of patterns in go command.

Fixes #24233

Change-Id: Idb8176df3a7949b16764cd6ea51d7a8966799e42
Reviewed-on: https://go-review.googlesource.com/c/go/+/669775
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Reviewed-by: Michael Matloob <matloob@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
src/cmd/go/internal/load/pkg.go
src/cmd/go/internal/search/search.go
src/cmd/go/testdata/script/install_backslash.txt [new file with mode: 0644]

index f11c2d9bed04ff7a36aeee2633d022fdc370eb9c..2b0eb7ca0dfcb62840f904845dacfc57feaedc1c 100644 (file)
@@ -3381,6 +3381,7 @@ func PackagesAndErrorsOutsideModule(ctx context.Context, opts PackageOpts, args
                        patterns[i] = p
                }
        }
+       patterns = search.CleanPatterns(patterns)
 
        // Query the module providing the first argument, load its go.mod file, and
        // check that it doesn't contain directives that would cause it to be
index 0d83cbd47d3008305c83c9f6f9cada5823ba616c..0954b82a028304590968e190dde65ab512b46b07 100644 (file)
@@ -419,9 +419,7 @@ func CleanPatterns(patterns []string) []string {
                if filepath.IsAbs(p) {
                        p = filepath.Clean(p)
                } else {
-                       if filepath.Separator == '\\' {
-                               p = strings.ReplaceAll(p, `\`, `/`)
-                       }
+                       p = strings.ReplaceAll(p, `\`, `/`)
 
                        // Put argument in canonical form, but preserve leading ./.
                        if strings.HasPrefix(p, "./") {
diff --git a/src/cmd/go/testdata/script/install_backslash.txt b/src/cmd/go/testdata/script/install_backslash.txt
new file mode 100644 (file)
index 0000000..adb359c
--- /dev/null
@@ -0,0 +1,12 @@
+# Issue #24233: allow backslash in path of command
+go install -n rsc.io\fortune@v1.0.0
+! stderr 'malformed'
+
+mkdir m
+cd m
+go mod init example.com/m
+go get rsc.io\fortune
+! stderr 'malformed'
+
+go install -n rsc.io\fortune@v1.0.0
+! stderr 'malformed'