fs: Fix panic on indexing URL of zero length
This commit is contained in:
parent
e5cf345273
commit
eb32c32063
6
fs.go
6
fs.go
@ -131,13 +131,13 @@ func serveFile(w ResponseWriter, r *Request, fsys fs.FS, name string, redirect b
|
|||||||
url := r.URL.Path
|
url := r.URL.Path
|
||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
// Add trailing slash
|
// Add trailing slash
|
||||||
if url[len(url)-1] != '/' {
|
if len(url) != 0 && url[len(url)-1] != '/' {
|
||||||
w.WriteHeader(StatusPermanentRedirect, path.Base(url)+"/")
|
w.WriteHeader(StatusPermanentRedirect, path.Base(url)+"/")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Remove trailing slash
|
// Remove trailing slash
|
||||||
if url[len(url)-1] == '/' {
|
if len(url) != 0 && url[len(url)-1] == '/' {
|
||||||
w.WriteHeader(StatusPermanentRedirect, "../"+path.Base(url))
|
w.WriteHeader(StatusPermanentRedirect, "../"+path.Base(url))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@ -147,7 +147,7 @@ func serveFile(w ResponseWriter, r *Request, fsys fs.FS, name string, redirect b
|
|||||||
if stat.IsDir() {
|
if stat.IsDir() {
|
||||||
// Redirect if the directory name doesn't end in a slash
|
// Redirect if the directory name doesn't end in a slash
|
||||||
url := r.URL.Path
|
url := r.URL.Path
|
||||||
if url[len(url)-1] != '/' {
|
if len(url) != 0 && url[len(url)-1] != '/' {
|
||||||
w.WriteHeader(StatusRedirect, path.Base(url)+"/")
|
w.WriteHeader(StatusRedirect, path.Base(url)+"/")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user