From 853abb31af1b832ad8be99c97cd252f1df4e1bfe Mon Sep 17 00:00:00 2001 From: RW Date: Thu, 4 Jun 2020 16:53:47 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20panic=20in=20fs.go=20#824=20(#82?= =?UTF-8?q?5)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: wernerr --- fs.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs.go b/fs.go index 28b34f8..a35189b 100644 --- a/fs.go +++ b/fs.go @@ -84,7 +84,7 @@ func ServeFile(ctx *RequestCtx, path string) { }) if len(path) == 0 || path[0] != '/' { // extend relative path to absolute path - hasTrailingSlash := path[len(path) - 1] == '/' + hasTrailingSlash := len(path) > 0 && path[len(path)-1] == '/' var err error if path, err = filepath.Abs(path); err != nil { ctx.Logger().Printf("cannot resolve path %q to absolute file path: %s", path, err) @@ -688,7 +688,7 @@ func (h *fsHandler) handleRequest(ctx *RequestCtx) { } else { path = ctx.Path() } - hasTrailingSlash := path[len(path) - 1] == '/' + hasTrailingSlash := len(path) > 0 && path[len(path)-1] == '/' path = stripTrailingSlashes(path) if n := bytes.IndexByte(path, 0); n >= 0 {