mirror of
https://github.com/golang/go
synced 2024-11-18 00:34:44 -07:00
path/filepath: fix Abs on Windows
The filepath.Abs function in windows did not call Clean as the documentation claimed. This change not only fixes that behavior but also adjusts TestAbs to verify Abs calls Clean as documented. Fixes #17210 Change-Id: I20c5f5026042fd7bd9d929ff5b17c8b2653f8afe Reviewed-on: https://go-review.googlesource.com/32292 Reviewed-by: Alex Brainman <alex.brainman@gmail.com> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Alex Brainman <alex.brainman@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
833f57ed50
commit
8f91865e1b
@ -1061,13 +1061,16 @@ var absTestDirs = []string{
|
|||||||
var absTests = []string{
|
var absTests = []string{
|
||||||
".",
|
".",
|
||||||
"b",
|
"b",
|
||||||
|
"b/",
|
||||||
"../a",
|
"../a",
|
||||||
"../a/b",
|
"../a/b",
|
||||||
"../a/b/./c/../../.././a",
|
"../a/b/./c/../../.././a",
|
||||||
|
"../a/b/./c/../../.././a/",
|
||||||
"$",
|
"$",
|
||||||
"$/.",
|
"$/.",
|
||||||
"$/a/../a/b",
|
"$/a/../a/b",
|
||||||
"$/a/b/c/../../.././a",
|
"$/a/b/c/../../.././a",
|
||||||
|
"$/a/b/c/../../.././a/",
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAbs(t *testing.T) {
|
func TestAbs(t *testing.T) {
|
||||||
@ -1132,7 +1135,7 @@ 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) {
|
if filepath.IsAbs(abspath) && abspath != filepath.Clean(abspath) {
|
||||||
t.Errorf("Abs(%q)=%q, isn't clean", path, abspath)
|
t.Errorf("Abs(%q)=%q, isn't clean", path, abspath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,11 @@ func splitList(path string) []string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func abs(path string) (string, error) {
|
func abs(path string) (string, error) {
|
||||||
return syscall.FullPath(path)
|
fullPath, err := syscall.FullPath(path)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return Clean(fullPath), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func join(elem []string) string {
|
func join(elem []string) string {
|
||||||
|
Loading…
Reference in New Issue
Block a user