Commit fc268acf authored by Russ Cox's avatar Russ Cox

path/filepath: steer people away from HasPrefix

The strikes against it are:

1. It does not take path boundaries into account.
2. It assumes that Windows==case-insensitive file system
and non-Windows==case-sensitive file system, neither of
which is always true.
3. Comparing ToLower against ToLower is not a correct
implementation of a case-insensitive string comparison.
4. If it returns true on Windows you still don't know how long
the matching prefix is in bytes, so you can't compute what
the suffix is.

R=golang-dev, r, dsymonds, r
CC=golang-dev
https://golang.org/cl/5712045
parent 8c529050
...@@ -17,7 +17,7 @@ func VolumeName(path string) string { ...@@ -17,7 +17,7 @@ func VolumeName(path string) string {
return "" return ""
} }
// HasPrefix tests whether the path p begins with prefix. // HasPrefix exists for historical compatibility and should not be used.
func HasPrefix(p, prefix string) bool { func HasPrefix(p, prefix string) bool {
return strings.HasPrefix(p, prefix) return strings.HasPrefix(p, prefix)
} }
...@@ -19,7 +19,7 @@ func VolumeName(path string) string { ...@@ -19,7 +19,7 @@ func VolumeName(path string) string {
return "" return ""
} }
// HasPrefix tests whether the path p begins with prefix. // HasPrefix exists for historical compatibility and should not be used.
func HasPrefix(p, prefix string) bool { func HasPrefix(p, prefix string) bool {
return strings.HasPrefix(p, prefix) return strings.HasPrefix(p, prefix)
} }
...@@ -67,8 +67,7 @@ func VolumeName(path string) (v string) { ...@@ -67,8 +67,7 @@ func VolumeName(path string) (v string) {
return "" return ""
} }
// HasPrefix tests whether the path p begins with prefix. // HasPrefix exists for historical compatibility and should not be used.
// It ignores case while comparing.
func HasPrefix(p, prefix string) bool { func HasPrefix(p, prefix string) bool {
if strings.HasPrefix(p, prefix) { if strings.HasPrefix(p, prefix) {
return true return true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment