go-chi / go-chi/chi

Encoded path will be decoded by `middleware.StripSlashes` and mismatch routers

Open
#798 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
22.8k
Forks
1.2k
Avg merge
5h 17m
Merged PRs (30d)
10

Description

To reproduce it:

```go
package main

import (
"net/http"
"time"

"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
)

func main() {
go server()
time.Sleep(time.Second)

_, _ = http.Get("http://localhost:3000/abc%2Fefg") // 200
_, _ = http.Get("http://localhost:3000/abc%2Fefg/") // 404
_, _ = http.Get("http://localhost:3000/abcefg/") // 200
}

func server() {
r := chi.NewRouter()
r.Use(middleware.Logger)
r.Use(middleware.StripSlashes)
r.Get("/{name}", func(w http.ResponseWriter, r *http.Request) {
_, _ = w.Write([]byte("welcome"))
})
_ = http.ListenAndServe(":3000", r)
}
```

And the log:

```text
2023/03/02 17:39:42 "GET http://localhost:3000/abc%2Fefg HTTP/1.1" from [::1]:49977 - 200 7B in 15.338µs
2023/03/02 17:39:42 "GET http://localhost:3000/abc%2Fefg/ HTTP/1.1" from [::1]:49978 - 404 19B in 5.918µs
2023/03/02 17:39:42 "GET http://localhost:3000/abcefg/ HTTP/1.1" from [::1]:49979 - 200 7B in 6.94µs
```

However, `/abc%2Fefg/` should return 200.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.