Commit 463f478d authored by Gustavo Niemeyer's avatar Gustavo Niemeyer

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
parent 0de328ed
......@@ -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 {
......
......@@ -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)
}
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment