From 34b455da4484dee20e8c355b50d24680224b58f2 Mon Sep 17 00:00:00 2001 From: Yasuhiro Matsumoto Date: Wed, 25 Jan 2017 16:48:17 +0900 Subject: [PATCH] path/filepath: ignore dot for Dir(`\\server\share`) Dir(`\\server\share`) returns `\\server\share.`. Change Dir so it returns `\\server\share` instead. Fixes #18783 Change-Id: I9e0dd71ea6aea85e6c6114aaa4bb3bea3270d818 Reviewed-on: https://go-review.googlesource.com/35690 Reviewed-by: Alex Brainman Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot --- src/path/filepath/path.go | 4 ++++ src/path/filepath/path_test.go | 1 + 2 files changed, 5 insertions(+) diff --git a/src/path/filepath/path.go b/src/path/filepath/path.go index 1d8e35c969e..e35ed5fefda 100644 --- a/src/path/filepath/path.go +++ b/src/path/filepath/path.go @@ -461,6 +461,10 @@ func Dir(path string) string { i-- } dir := Clean(path[len(vol) : i+1]) + if dir == "." && len(vol) > 2 { + // must be UNC + return vol + } return vol + dir } diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index 921b23842b4..70baa6112f6 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -665,6 +665,7 @@ var windirtests = []PathTest{ {`c:\a\b`, `c:\a`}, {`c:a\b`, `c:a`}, {`c:a\b\c`, `c:a\b`}, + {`\\host\share`, `\\host\share`}, {`\\host\share\`, `\\host\share\`}, {`\\host\share\a`, `\\host\share\`}, {`\\host\share\a\b`, `\\host\share\a`},