diff options
| author | LE Manh Cuong <cuong.manhle.vn@gmail.com> | 2018-12-21 11:21:02 +0700 |
|---|---|---|
| committer | Ian Lance Taylor <iant@golang.org> | 2018-12-24 18:38:18 +0000 |
| commit | b32ee0a3c004d4ef79d92bd63200008456da50f3 (patch) | |
| tree | 47f05e44f8547e859709a4cf7e6e3b83d491b6de /src/path/filepath/path_test.go | |
| parent | 3b66c00857ff77f8acfc3e6e9491dda3677858a4 (diff) | |
| download | go-b32ee0a3c004d4ef79d92bd63200008456da50f3.tar.xz | |
path/filepath: walkSymlinks: return correct error for file with trailing slash
Rather than return os.ErrNotExist for /path/to/existing_file/,
walkSymLinks now returns syscall.ENOTDIR.
This is consistent with behavior of os.Lstat.
Fixes #29372
Change-Id: Id5c471d901db04b2f35d60f60a81b2a0be93cae9
Reviewed-on: https://go-review.googlesource.com/c/155597
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/path/filepath/path_test.go')
| -rw-r--r-- | src/path/filepath/path_test.go | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/path/filepath/path_test.go b/src/path/filepath/path_test.go index 3434ea2e6e..1b9f286c4d 100644 --- a/src/path/filepath/path_test.go +++ b/src/path/filepath/path_test.go @@ -15,6 +15,7 @@ import ( "runtime" "sort" "strings" + "syscall" "testing" ) @@ -1371,3 +1372,39 @@ func TestWalkSymlink(t *testing.T) { testenv.MustHaveSymlink(t) testWalkSymlink(t, os.Symlink) } + +func TestIssue29372(t *testing.T) { + f, err := ioutil.TempFile("", "issue29372") + if err != nil { + t.Fatal(err) + } + f.Close() + path := f.Name() + defer os.Remove(path) + + isWin := runtime.GOOS == "windows" + pathSeparator := string(filepath.Separator) + tests := []struct { + path string + skip bool + }{ + {path + strings.Repeat(pathSeparator, 1), false}, + {path + strings.Repeat(pathSeparator, 2), false}, + {path + strings.Repeat(pathSeparator, 1) + ".", false}, + {path + strings.Repeat(pathSeparator, 2) + ".", false}, + // windows.GetFinalPathNameByHandle return the directory part with trailing dot dot + // C:\path\to\existing_dir\existing_file\.. returns C:\path\to\existing_dir + {path + strings.Repeat(pathSeparator, 1) + "..", isWin}, + {path + strings.Repeat(pathSeparator, 2) + "..", isWin}, + } + + for i, test := range tests { + if test.skip { + continue + } + _, err = filepath.EvalSymlinks(test.path) + if err != syscall.ENOTDIR { + t.Fatalf("test#%d: want %q, got %q", i, syscall.ENOTDIR, err) + } + } +} |
