Skip to content

Commit 1106512

Browse files
committed
path/filepath: deprecate HasPrefix
Use the new "Deprecated:" syntax for all instances of HasPrefix. This is a follow-up to http://golang.org/cl/28413 which only modified path_unix.go. In this CL, we avoid mentioning that strings.HasPrefix should be used since that function is still subtly wrong in security applications. See http://golang.org/cl/5712045 for more information. Fixes #18355 Change-Id: I0d0306152cd0b0ea5110774c2c78117515b9f5cd Reviewed-on: https://go-review.googlesource.com/34554 Run-TryBot: Joe Tsai <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 61db2e4 commit 1106512

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

src/path/filepath/path_plan9.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ func volumeNameLen(path string) int {
1818
}
1919

2020
// HasPrefix exists for historical compatibility and should not be used.
21+
//
22+
// Deprecated: HasPrefix does not respect path boundaries and
23+
// does not ignore case when required.
2124
func HasPrefix(p, prefix string) bool {
2225
return strings.HasPrefix(p, prefix)
2326
}

src/path/filepath/path_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ func volumeNameLen(path string) int {
2121

2222
// HasPrefix exists for historical compatibility and should not be used.
2323
//
24-
// Deprecated: Use strings.HasPrefix instead.
24+
// Deprecated: HasPrefix does not respect path boundaries and
25+
// does not ignore case when required.
2526
func HasPrefix(p, prefix string) bool {
2627
return strings.HasPrefix(p, prefix)
2728
}

src/path/filepath/path_windows.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func volumeNameLen(path string) int {
6565
}
6666

6767
// HasPrefix exists for historical compatibility and should not be used.
68+
//
69+
// Deprecated: HasPrefix does not respect path boundaries and
70+
// does not ignore case when required.
6871
func HasPrefix(p, prefix string) bool {
6972
if strings.HasPrefix(p, prefix) {
7073
return true

0 commit comments

Comments
 (0)