1
0
mirror of https://github.com/golang/go synced 2024-11-17 18:54:42 -07:00

archive/zip: use strings.TrimPrefix

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>
This commit is contained in:
cuiweixie 2022-09-28 21:13:41 +08:00 committed by Gopher Robot
parent 1371efcd69
commit 45c2421dc6

View 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
}