]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: steer people away from HasPrefix
authorRuss Cox <rsc@golang.org>
Wed, 29 Feb 2012 21:37:40 +0000 (16:37 -0500)
committerRuss Cox <rsc@golang.org>
Wed, 29 Feb 2012 21:37:40 +0000 (16:37 -0500)
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

src/pkg/path/filepath/path_plan9.go
src/pkg/path/filepath/path_unix.go
src/pkg/path/filepath/path_windows.go

index 17b873f1a9b94603c4bfc966ca809730869677ee..cf028a75c525e2495cb081590863dbc9c47d3444 100644 (file)
@@ -17,7 +17,7 @@ func VolumeName(path string) string {
        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 {
        return strings.HasPrefix(p, prefix)
 }
index c5ac71efe218f28117543436082e636140ed22e4..305e307272f8b7a831f6291b0370d96d31a1c964 100644 (file)
@@ -19,7 +19,7 @@ func VolumeName(path string) string {
        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 {
        return strings.HasPrefix(p, prefix)
 }
index 9692fd978c5da3b094d12313c3ebda6a214c29bb..1d1d23bfe7ccd8ff22f186e8babcc8a747794f3d 100644 (file)
@@ -67,8 +67,7 @@ func VolumeName(path string) (v string) {
        return ""
 }
 
-// HasPrefix tests whether the path p begins with prefix.
-// It ignores case while comparing.
+// HasPrefix exists for historical compatibility and should not be used.
 func HasPrefix(p, prefix string) bool {
        if strings.HasPrefix(p, prefix) {
                return true