-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Description
Attempting to use routes that specify the quantity to match in regex does not work. This looks to be related to the way finding curly braces (i.e. {
and }
) works in pattern segments:
Line 628 in 49e7138
ps := strings.Index(pattern, "{") |
Here are two routes that fail in different ways from my expectations:
package main
import (
"fmt"
"net/http"
"github.com/go-chi/chi"
)
func handler(w http.ResponseWriter, req *http.Request) {
w.WriteHeader(200)
w.Write([]byte("HERE"))
}
func main() {
r := chi.NewRouter()
r.MethodFunc("GET", "/{first:[a-z]{4}}", handler) // Does not panic at runtime, however I except it to match only requests with four a-z characters.
r.MethodFunc("GET", "/{first:[a-z]{4}}/{second}", handler) // Panics at runtime, slice bounds out of range. I expect it to match only requests where the first URI segment has four a-z characters and some value in the second segment. Comment out to test the first defined route.
fmt.Println("Listening...")
http.ListenAndServe(":3000", r)
}
Metadata
Metadata
Assignees
Labels
No labels