From 00a07adccf5a93610ab424d00ed739ee716c3a4b Mon Sep 17 00:00:00 2001 From: water <672684719@qq.com> Date: Fri, 31 Jul 2026 23:59:37 +0800 Subject: [PATCH] fix: clean path in createStaticHandler before opening file (#4451) --- routergroup.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routergroup.go b/routergroup.go index c01b917e..8f065a10 100644 --- a/routergroup.go +++ b/routergroup.go @@ -223,6 +223,10 @@ func (group *RouterGroup) createStaticHandler(relativePath string, fs http.FileS } file := c.Param("filepath") + // Clean the path to handle trailing slashes and invalid paths. + // Many fs.FS implementations (e.g. fs.Sub, http.FS) reject paths with + // trailing slashes because fs.ValidPath considers them invalid. + file = path.Clean(file) // Check if file exists and/or if we have permission to access it f, err := fs.Open(file) if err != nil {