]> Cypherpunks.ru repositories - gostls13.git/commitdiff
path/filepath: in Rel use case-insensitive comparison on Windows
authorYasuhiro Matsumoto <mattn.jp@gmail.com>
Wed, 11 Nov 2015 01:21:49 +0000 (10:21 +0900)
committerRuss Cox <rsc@golang.org>
Thu, 12 Nov 2015 19:58:37 +0000 (19:58 +0000)
Fixes #10802

Compare Volume name and each path elements using strings.EqualFold.

Change-Id: Ibdefdb801d0326e53755bc9cc8c10eed998094e5
Reviewed-on: https://go-review.googlesource.com/16795
Reviewed-by: Russ Cox <rsc@golang.org>
src/path/filepath/path.go
src/path/filepath/path_plan9.go
src/path/filepath/path_test.go
src/path/filepath/path_unix.go
src/path/filepath/path_windows.go

index 5dc5cfd49e734eb7c79a82fc219f41db7bbbb0a1..681fdfa09fab2652ec0dd139c105ce2a4f200740 100644 (file)
@@ -269,7 +269,7 @@ func Rel(basepath, targpath string) (string, error) {
        // Can't use IsAbs - `\a` and `a` are both relative in Windows.
        baseSlashed := len(base) > 0 && base[0] == Separator
        targSlashed := len(targ) > 0 && targ[0] == Separator
-       if baseSlashed != targSlashed || baseVol != targVol {
+       if baseSlashed != targSlashed || !sameWord(baseVol, targVol) {
                return "", errors.New("Rel: can't make " + targ + " relative to " + base)
        }
        // Position base[b0:bi] and targ[t0:ti] at the first differing elements.
@@ -283,7 +283,7 @@ func Rel(basepath, targpath string) (string, error) {
                for ti < tl && targ[ti] != Separator {
                        ti++
                }
-               if targ[t0:ti] != base[b0:bi] {
+               if !sameWord(targ[t0:ti], base[b0:bi]) {
                        break
                }
                if bi < bl {
index 962774efd5d9aa180662d31d95f7df8cd444f15c..60d46d9d421d21efb821a06afbffbb14c26bc343 100644 (file)
@@ -42,3 +42,7 @@ func join(elem []string) string {
        }
        return ""
 }
+
+func sameWord(a, b string) bool {
+       return a == b
+}
index 09e7be228aad5fe5c5e31b69bdf0e5bf0dcbc1a5..057aa6a2c0015fc7e695dd1b46bbf5fc658b3d9c 100644 (file)
@@ -1033,6 +1033,7 @@ var winreltests = []RelTests{
        {`C:a\b\c`, `C:a/b/d`, `..\d`},
        {`C:\`, `D:\`, `err`},
        {`C:`, `D:`, `err`},
+       {`C:\Projects`, `c:\projects\src`, `src`},
 }
 
 func TestRel(t *testing.T) {
index d241d78fa781cfba06253ba4bd196243e1251dd4..2d242cc0b5d798320cbad85599953188e9d82be6 100644 (file)
@@ -44,3 +44,7 @@ func join(elem []string) string {
        }
        return ""
 }
+
+func sameWord(a, b string) bool {
+       return a == b
+}
index bcfe0a34b0a181b2118c070d771109c12baeae8b..edf7966d19708580dadde5db30a53d29505967a9 100644 (file)
@@ -145,3 +145,7 @@ func joinNonEmpty(elem []string) string {
 func isUNC(path string) bool {
        return volumeNameLen(path) > 2
 }
+
+func sameWord(a, b string) bool {
+       return strings.EqualFold(a, b)
+}