diff options
| author | Gustavo Niemeyer <gustavo@niemeyer.net> | 2011-05-30 22:28:59 -0300 |
|---|---|---|
| committer | Gustavo Niemeyer <gustavo@niemeyer.net> | 2011-05-30 22:28:59 -0300 |
| commit | 463f478dbb2a502b265c08e0eff1b3334a1bfcf9 (patch) | |
| tree | 284eae54eeb8f9c7c0f21edea81651554b0048f4 /src/pkg/path/filepath | |
| parent | 0de328edd63d8e85588309982ce86948548db96b (diff) | |
| download | go-463f478dbb2a502b265c08e0eff1b3334a1bfcf9.tar.xz | |
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
Diffstat (limited to 'src/pkg/path/filepath')
| -rw-r--r-- | src/pkg/path/filepath/path.go | 2 | ||||
| -rw-r--r-- | src/pkg/path/filepath/path_test.go | 4 |
2 files changed, 5 insertions, 1 deletions
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) + } } } |
