Skip to content

Commit bd3db2c

Browse files
committed
path/filepath: allow EvalSymlinks to work on UNC share roots on Windows
Fixes #42079 Previously, EvalSymlinks returned an error when called with the root of a UNC share (e.g. \\server\share). This was due to Windows's FindFirstFile function not supporting a share root path. To resolve this, now return early from toNorm in the case where the path after the volume name is empty. Skipping the later path component resolution shouldn't have any negative impact in this case, as if the path is empty, there aren't any path components to resolve anyways. The test case uses the localhost admin share (c$), as it should be present in most situations. This allows testing without setting up an external file share. However, this fix applies to all UNC share root paths.
1 parent 5647d01 commit bd3db2c

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/path/filepath/path_windows_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,9 @@ func TestToNorm(t *testing.T) {
412412
{`{{tmp}}\test`, `.\foo\bar`, `foo\bar`},
413413
{`{{tmp}}\test`, `foo\..\foo\bar`, `foo\bar`},
414414
{`{{tmp}}\test`, `FOO\BAR`, `foo\bar`},
415+
416+
// test UNC paths
417+
{".", `\\localhost\c$`, `\\localhost\c$`},
415418
}
416419

417420
tmp, err := ioutil.TempDir("", "testToNorm")

src/path/filepath/symlink_windows.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func toNorm(path string, normBase func(string) (string, error)) (string, error)
6868
path = path[len(volume):]
6969

7070
// skip special cases
71-
if path == "." || path == `\` {
71+
if path == "" || path == "." || path == `\` {
7272
return volume + path, nil
7373
}
7474

0 commit comments

Comments
 (0)