improvements for error handling

This commit is contained in:
Mauri de Souza Meneguzzo 2023-11-19 17:45:30 -03:00
parent 6715bf3be8
commit dbbbe96fd5
2 changed files with 4 additions and 5 deletions

View File

@ -78,9 +78,8 @@ func (d Dir) Open(name string) (File, error) {
if dir == "" {
dir = "."
}
fi, err := os.Stat(dir)
if err != nil || !fi.IsDir() {
return nil, errors.New("http: invalid directory path")
if fi, _ := os.Stat(dir); fi != nil && !fi.IsDir() {
return nil, errors.New("http: attempting to traverse a non-directory")
}
fullName := filepath.Join(dir, path)
f, err := os.Open(fullName)

View File

@ -1689,8 +1689,8 @@ func testFileServerDirWithRootFile(t *testing.T, mode testMode) {
if err != nil {
t.Fatal(err)
}
if s := res.StatusCode; s != StatusInternalServerError {
t.Errorf("got %q, want 500", s)
if g, w := res.StatusCode, StatusInternalServerError; g != w {
t.Errorf("StatusCode mismatch: got %d, want: %d", g, w)
}
res.Body.Close()
}