static middleware with HTML5 set to true returns error for invalid path characters running on Windows
Issue Description
I'm using the StaticWithConfig middleware to serve a SPA (single page application).
In my app, ID of things contains : char and my detail page in the SPA requires that ID in the path. so when the middleware tries to open the file and check if it exists or not, the openFile function returns an error other than IsNotExists and the middleware returns the error and doesn't serve the static index file.
I tried this on Linux and it's working, but breaks on windows which I'm running on my dev machine.
this is the error I get:
open web\\public\\details\\123:123:123: The filename, directory name, or volume label syntax is incorrect.
Working code to debug
you can reproduce the error using this code and calling this URL http://localhost:1323/details/123:123:123
package main
import (
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
)
func main() {
e := echo.New()
e.Debug = true
e.Use(middleware.StaticWithConfig(middleware.StaticConfig{
Root: "./web/public",
Index: "index.html",
HTML5: true,
}))
e.Logger.Fatal(e.Start(":1323"))
}
Version/commit
v4.7.2
Solution!?
I found that ignoring the fs.PathError error, will fix the issue.
file, err := openFile(config.Filesystem, name)
if err != nil {
var perr *fs.PathError
if !os.IsNotExist(err) && !errors.As(err, &perr) {
if !os.IsNotExist(err) && !errors.As(err, &perr) {
return err
}
I can create a pull request if it makes sense.