]> Cypherpunks repositories - gostls13.git/commitdiff
archive/zip: use strings.TrimPrefix
authorcuiweixie <cuiweixie@gmail.com>
Wed, 28 Sep 2022 13:13:41 +0000 (21:13 +0800)
committerGopher Robot <gobot@golang.org>
Thu, 29 Sep 2022 20:45:56 +0000 (20:45 +0000)
Change-Id: I2854b5e7b48c4c189df84cb7281b7b7de780eebd
Reviewed-on: https://go-review.googlesource.com/c/go/+/435938
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
src/archive/zip/reader.go

index d7fcff2afd120ef61dca49b0429398a208c8dc9e..db118ce854df021ae847fd90a3a014f5384de128 100644 (file)
@@ -715,12 +715,13 @@ func (f *fileListEntry) Info() (fs.FileInfo, error) { return f, nil }
 func toValidName(name string) string {
        name = strings.ReplaceAll(name, `\`, `/`)
        p := path.Clean(name)
-       if strings.HasPrefix(p, "/") {
-               p = p[len("/"):]
-       }
+
+       p = strings.TrimPrefix(p, "/")
+
        for strings.HasPrefix(p, "../") {
                p = p[len("../"):]
        }
+
        return p
 }