diff --git a/adapters/humaflow/flow/flow.go b/adapters/humaflow/flow/flow.go index 4a9ceed7..22b9083e 100644 --- a/adapters/humaflow/flow/flow.go +++ b/adapters/humaflow/flow/flow.go @@ -62,6 +62,7 @@ package flow import ( "context" "net/http" + "net/url" "regexp" "slices" "strings" @@ -165,7 +166,7 @@ func (m *Mux) Group(fn func(*Mux)) { // ServeHTTP makes the router implement the http.Handler interface. func (m *Mux) ServeHTTP(w http.ResponseWriter, r *http.Request) { - urlSegments := strings.Split(r.URL.Path, "/") + urlSegments := strings.Split(r.URL.EscapedPath(), "/") allowedMethods := []string{} for _, route := range *m.routes { @@ -227,15 +228,20 @@ func (r *route) match(ctx context.Context, urlSegments []string) (context.Contex if strings.HasPrefix(routeSegment, ":") { key, rxPattern, containsRx := strings.Cut(strings.TrimPrefix(routeSegment, ":"), "|") + value, err := url.QueryUnescape(urlSegments[i]) + if err != nil { + return ctx, false + } + if containsRx { - if compiledRXPatterns[rxPattern].MatchString(urlSegments[i]) { - ctx = context.WithValue(ctx, contextKey(key), urlSegments[i]) + if compiledRXPatterns[rxPattern].MatchString(value) { + ctx = context.WithValue(ctx, contextKey(key), value) continue } } - if !containsRx && urlSegments[i] != "" { - ctx = context.WithValue(ctx, contextKey(key), urlSegments[i]) + if !containsRx && value != "" { + ctx = context.WithValue(ctx, contextKey(key), value) continue } diff --git a/adapters/humaflow/flow/flow_test.go b/adapters/humaflow/flow/flow_test.go index d6b51f55..854711e9 100644 --- a/adapters/humaflow/flow/flow_test.go +++ b/adapters/humaflow/flow/flow_test.go @@ -95,6 +95,11 @@ func TestMatching(t *testing.T) { "GET", "/path-params/60/beatles/lennon/bar", http.StatusNotFound, map[string]string{"era": "60", "group": "beatles", "member": "lennon"}, "", }, + { + []string{"GET"}, "/path-params/:era", + "GET", "/path-params/a%3A%2F%2Fb%2Fc", + http.StatusOK, map[string]string{"era": "a://b/c"}, "", + }, // regexp { []string{"GET"}, "/path-params/:era|^[0-9]{2}$/:group|^[a-z].+$",