From: Gustavo Niemeyer Date: Tue, 31 May 2011 01:28:59 +0000 (-0300) Subject: filepath: Abs must always return a clean path X-Git-Tag: weekly.2011-06-02~58 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=463f478dbb2a502b265c08e0eff1b3334a1bfcf9;p=gostls13.git filepath: Abs must always return a clean path When I was first coding Abs, I wondered if people wouldn't expect the path to be consistently clean, even if the path passed in was already absolute. CL 4524078 has a potential problem based on exactly that assumption, so it feels like this behavior is indeed the most useful and least surprising. R=golang-dev, adg CC=golang-dev https://golang.org/cl/4548074 --- diff --git a/src/pkg/path/filepath/path.go b/src/pkg/path/filepath/path.go index 147256a1d3..124de989a7 100644 --- a/src/pkg/path/filepath/path.go +++ b/src/pkg/path/filepath/path.go @@ -247,7 +247,7 @@ func EvalSymlinks(path string) (string, os.Error) { // path name for a given file is not guaranteed to be unique. func Abs(path string) (string, os.Error) { if IsAbs(path) { - return path, nil + return Clean(path), nil } wd, err := os.Getwd() if err != nil { diff --git a/src/pkg/path/filepath/path_test.go b/src/pkg/path/filepath/path_test.go index b147349836..624c9d8ffd 100644 --- a/src/pkg/path/filepath/path_test.go +++ b/src/pkg/path/filepath/path_test.go @@ -509,6 +509,7 @@ var abstests = []string{ // Already absolute "$GOROOT/src/Make.pkg", + "$GOROOT/src/../src/Make.pkg", } func TestAbs(t *testing.T) { @@ -537,5 +538,8 @@ func TestAbs(t *testing.T) { if !filepath.IsAbs(abspath) { t.Errorf("Abs(%q)=%q, not an absolute path", path, abspath) } + if filepath.IsAbs(path) && abspath != filepath.Clean(path) { + t.Errorf("Abs(%q)=%q, isn't clean", path, abspath) + } } }