Updates #30165
Updates #31622
Change-Id: I7a4b91aa7c5c3af8c0b1273cbb42046feddf7d78
Reviewed-on: https://go-review.googlesource.com/c/go/+/180499
Reviewed-by: Emmanuel Odeke <emm.odeke@gmail.com>
Run-TryBot: Emmanuel Odeke <emm.odeke@gmail.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
// redirect if the directory name doesn't end in a slash
if d.IsDir() {
url := r.URL.Path
- if url[len(url)-1] != '/' {
+ if url == "" || url[len(url)-1] != '/' {
localRedirect(w, r, path.Base(url)+"/")
return
}
}
}
+// Tests that this doesn't panic. (Issue 30165)
+func TestServeFileDirPanicEmptyPath(t *testing.T) {
+ rec := httptest.NewRecorder()
+ req := httptest.NewRequest("GET", "/", nil)
+ req.URL.Path = ""
+ ServeFile(rec, req, "testdata")
+ res := rec.Result()
+ if res.StatusCode != 301 {
+ t.Errorf("code = %v; want 301", res.Status)
+ }
+}
+
var fsRedirectTestData = []struct {
original, redirect string
}{