From 199b17cca8daf5bac6210e5719b1e85a51bd311d Mon Sep 17 00:00:00 2001 From: Hiroshi Ioka Date: Fri, 26 Aug 2016 13:50:34 +0900 Subject: [PATCH] path/filepath: handle "C:." correctly in EvalSymlinks on Windows Fixes #16886 Change-Id: Idfacb0cf44d9994559c8e09032b4595887e76433 Reviewed-on: https://go-review.googlesource.com/28214 Reviewed-by: Alex Brainman Run-TryBot: Alex Brainman TryBot-Result: Gobot Gobot --- src/path/filepath/path_test.go | 34 ++++++++++++++++++++++++++++++++++ src/path/filepath/symlink.go | 5 +++-- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index e32922b4cc..737db6c93a 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -877,6 +877,40 @@ func TestEvalSymlinks(t *testing.T) { t.Errorf(`EvalSymlinks(".") in %q directory returns %q, want "." or %q`, d.path, p, want) }() + // test EvalSymlinks("C:.") on Windows + if runtime.GOOS == "windows" { + func() { + defer func() { + err := os.Chdir(wd) + if err != nil { + t.Fatal(err) + } + }() + + err := os.Chdir(path) + if err != nil { + t.Error(err) + return + } + + volDot := filepath.VolumeName(tmpDir) + "." + + p, err := filepath.EvalSymlinks(volDot) + if err != nil { + t.Errorf(`EvalSymlinks("%s") in %q directory error: %v`, volDot, d.path, err) + return + } + if p == volDot { + return + } + want := filepath.Clean(findEvalSymlinksTestDirsDest(t, testdirs, d.path)) + if p == want { + return + } + t.Errorf(`EvalSymlinks("%s") in %q directory returns %q, want %q or %q`, volDot, d.path, p, volDot, want) + }() + } + // test EvalSymlinks(".."+path) func() { defer func() { diff --git a/src/path/filepath/symlink.go b/src/path/filepath/symlink.go index f627a94ddb..824aee4e49 100644 --- a/src/path/filepath/symlink.go +++ b/src/path/filepath/symlink.go @@ -105,8 +105,9 @@ func walkSymlinks(path string) (string, error) { // directory is a symlink. Stop the walk, if symlink // target is not absolute path, and return "." // to the caller (just like unix does). - if path == "." && !IsAbs(newpath) { - return ".", nil + // Same for "C:.". + if path[volumeNameLen(path):] == "." && !IsAbs(newpath) { + return path, nil } } if i == linksWalked {