mirror of
https://github.com/golang/go
synced 2024-11-25 04:57:56 -07:00
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
This commit is contained in:
parent
0de328edd6
commit
463f478dbb
@ -247,7 +247,7 @@ func EvalSymlinks(path string) (string, os.Error) {
|
|||||||
// path name for a given file is not guaranteed to be unique.
|
// path name for a given file is not guaranteed to be unique.
|
||||||
func Abs(path string) (string, os.Error) {
|
func Abs(path string) (string, os.Error) {
|
||||||
if IsAbs(path) {
|
if IsAbs(path) {
|
||||||
return path, nil
|
return Clean(path), nil
|
||||||
}
|
}
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -509,6 +509,7 @@ var abstests = []string{
|
|||||||
|
|
||||||
// Already absolute
|
// Already absolute
|
||||||
"$GOROOT/src/Make.pkg",
|
"$GOROOT/src/Make.pkg",
|
||||||
|
"$GOROOT/src/../src/Make.pkg",
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAbs(t *testing.T) {
|
func TestAbs(t *testing.T) {
|
||||||
@ -537,5 +538,8 @@ func TestAbs(t *testing.T) {
|
|||||||
if !filepath.IsAbs(abspath) {
|
if !filepath.IsAbs(abspath) {
|
||||||
t.Errorf("Abs(%q)=%q, not an absolute path", path, 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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user