aboutsummaryrefslogtreecommitdiff
path: root/src/path/filepath/path_test.go
diff options
context:
space:
mode:
authorEmil Hessman <emil@hessman.se>2014-12-31 06:27:31 +0100
committerAlex Brainman <alex.brainman@gmail.com>2015-01-20 23:23:01 +0000
commit8128b0116decc3b33e37a35d8d83182e2a19b61d (patch)
tree358946b1bc3e27d04fe3df58fba68cde1b45db4f /src/path/filepath/path_test.go
parent4e0618c99262260e5992dc77b60fa2fc93f8c9b6 (diff)
downloadgo-8128b0116decc3b33e37a35d8d83182e2a19b61d.tar.xz
path/filepath: make Join handle UNC paths on Windows
Unless the first element is a Universal Naming Convention (UNC)[0] path, Join shouldn't create a UNC path on Windows. For example, Join inadvertently creates a UNC path on Windows when told to join at least three non-empty path elements, where the first element is `\` or `/`. This CL prevents creation of a UNC path prefix when the first path element isn't a UNC path. Since this introduces some amount of Windows-specific logic, Join is moved to a per GOOS implementation. Fixes #9167. [0]: http://msdn.microsoft.com/en-us/library/gg465305.aspx Change-Id: Ib6eda597106cb025137673b33c4828df1367f75b Reviewed-on: https://go-review.googlesource.com/2211 Reviewed-by: Alex Brainman <alex.brainman@gmail.com>
Diffstat (limited to 'src/path/filepath/path_test.go')
-rw-r--r--src/path/filepath/path_test.go28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go
index 399284b97d..c4f74b97ff 100644
--- a/src/path/filepath/path_test.go
+++ b/src/path/filepath/path_test.go
@@ -242,6 +242,7 @@ var jointests = []JoinTest{
// one parameter
{[]string{""}, ""},
+ {[]string{"/"}, "/"},
{[]string{"a"}, "a"},
// two parameters
@@ -249,10 +250,16 @@ var jointests = []JoinTest{
{[]string{"a", ""}, "a"},
{[]string{"", "b"}, "b"},
{[]string{"/", "a"}, "/a"},
+ {[]string{"/", "a/b"}, "/a/b"},
{[]string{"/", ""}, "/"},
+ {[]string{"//", "a"}, "/a"},
+ {[]string{"/a", "b"}, "/a/b"},
{[]string{"a/", "b"}, "a/b"},
{[]string{"a/", ""}, "a"},
{[]string{"", ""}, ""},
+
+ // three parameters
+ {[]string{"/", "a", "b"}, "/a/b"},
}
var winjointests = []JoinTest{
@@ -262,13 +269,17 @@ var winjointests = []JoinTest{
{[]string{`C:\`, `Windows`}, `C:\Windows`},
{[]string{`C:`, `Windows`}, `C:\Windows`},
{[]string{`\\host\share`, `foo`}, `\\host\share\foo`},
+ {[]string{`\\host\share\foo`}, `\\host\share\foo`},
{[]string{`//host/share`, `foo/bar`}, `\\host\share\foo\bar`},
-}
-
-// join takes a []string and passes it to Join.
-func join(elem []string, args ...string) string {
- args = elem
- return filepath.Join(args...)
+ {[]string{`\`}, `\`},
+ {[]string{`\`, ``}, `\`},
+ {[]string{`\`, `a`}, `\a`},
+ {[]string{`\\`, `a`}, `\a`},
+ {[]string{`\`, `a`, `b`}, `\a\b`},
+ {[]string{`\\`, `a`, `b`}, `\a\b`},
+ {[]string{`\`, `\\a\b`, `c`}, `\a\b\c`},
+ {[]string{`\\a`, `b`, `c`}, `\a\b\c`},
+ {[]string{`\\a\`, `b`, `c`}, `\a\b\c`},
}
func TestJoin(t *testing.T) {
@@ -276,8 +287,9 @@ func TestJoin(t *testing.T) {
jointests = append(jointests, winjointests...)
}
for _, test := range jointests {
- if p := join(test.elem); p != filepath.FromSlash(test.path) {
- t.Errorf("join(%q) = %q, want %q", test.elem, p, test.path)
+ expected := filepath.FromSlash(test.path)
+ if p := filepath.Join(test.elem...); p != expected {
+ t.Errorf("join(%q) = %q, want %q", test.elem, p, expected)
}
}
}