]> Cypherpunks repositories - gostls13.git/commitdiff
filepath: Abs must always return a clean path
authorGustavo Niemeyer <gustavo@niemeyer.net>
Tue, 31 May 2011 01:28:59 +0000 (22:28 -0300)
committerGustavo Niemeyer <gustavo@niemeyer.net>
Tue, 31 May 2011 01:28:59 +0000 (22:28 -0300)
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

src/pkg/path/filepath/path.go
src/pkg/path/filepath/path_test.go

index 147256a1d3ca9b3e668b36c194fd471492bcfaf0..124de989a75ce501b4b7181f86a2953e595a3ba5 100644 (file)
@@ -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 {
index b147349836a4b77784fc20f2c06a14770d21b3b5..624c9d8ffdd895c296edc7c0ec0c93b398af609d 100644 (file)
@@ -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)
+               }
        }
 }