]> Cypherpunks repositories - gostls13.git/commitdiff
path/filepath: handle c: as first parameter in Join properly
authorAlex Brainman <alex.brainman@gmail.com>
Sat, 5 Dec 2015 03:29:39 +0000 (14:29 +1100)
committerAlex Brainman <alex.brainman@gmail.com>
Sun, 6 Dec 2015 06:11:09 +0000 (06:11 +0000)
This is CL 11882 brought back to life.

Fixes #11551

Change-Id: I29810183957745442d1e9937f56a66fc9c6cc82a
Reviewed-on: https://go-review.googlesource.com/17470
Reviewed-by: Russ Cox <rsc@golang.org>
Run-TryBot: Alex Brainman <alex.brainman@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>

src/path/filepath/path_test.go
src/path/filepath/path_windows.go

index e41a97da1135a7fca21f41ad3e035d8e4bcc0207..201f4fa86903fc10f251644d9de844438bd495e7 100644 (file)
@@ -267,7 +267,12 @@ var winjointests = []JoinTest{
        {[]string{`C:\Windows\`, `System32`}, `C:\Windows\System32`},
        {[]string{`C:\Windows\`, ``}, `C:\Windows`},
        {[]string{`C:\`, `Windows`}, `C:\Windows`},
-       {[]string{`C:`, `Windows`}, `C:\Windows`},
+       {[]string{`C:`, `a`}, `C:a`},
+       {[]string{`C:`, `a\b`}, `C:a\b`},
+       {[]string{`C:`, `a`, `b`}, `C:a\b`},
+       {[]string{`C:.`, `a`}, `C:a`},
+       {[]string{`C:a`, `b`}, `C:a\b`},
+       {[]string{`C:a`, `b`, `d`}, `C:a\b\d`},
        {[]string{`\\host\share`, `foo`}, `\\host\share\foo`},
        {[]string{`\\host\share\foo`}, `\\host\share\foo`},
        {[]string{`//host/share`, `foo/bar`}, `\\host\share\foo\bar`},
index edf7966d19708580dadde5db30a53d29505967a9..ef6e7ca93f4adaaed37d334cd1d6e90ef628ef05 100644 (file)
@@ -120,6 +120,11 @@ func join(elem []string) string {
 
 // joinNonEmpty is like join, but it assumes that the first element is non-empty.
 func joinNonEmpty(elem []string) string {
+       if len(elem[0]) == 2 && elem[0][1] == ':' {
+               // First element is drive leter without terminating slash.
+               // Keep path relative to current directory on that drive.
+               return Clean(elem[0] + strings.Join(elem[1:], string(Separator)))
+       }
        // The following logic prevents Join from inadvertently creating a
        // UNC path on Windows. Unless the first element is a UNC path, Join
        // shouldn't create a UNC path. See golang.org/issue/9167.