diff --git a/runtime/mux.go b/runtime/mux.go index 6d483e8cccd..69edf5eff8d 100644 --- a/runtime/mux.go +++ b/runtime/mux.go @@ -481,6 +481,7 @@ func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { HTTPStatus: http.StatusBadRequest, Err: mse, }) + return } continue } @@ -523,6 +524,7 @@ func (s *ServeMux) ServeHTTP(w http.ResponseWriter, r *http.Request) { HTTPStatus: http.StatusBadRequest, Err: mse, }) + return } continue } diff --git a/runtime/mux_test.go b/runtime/mux_test.go index 1efd21224d4..62be90324b7 100644 --- a/runtime/mux_test.go +++ b/runtime/mux_test.go @@ -3,10 +3,12 @@ package runtime_test import ( "bytes" "context" + "encoding/json" "fmt" "net/http" "net/http/httptest" "net/url" + "reflect" "strconv" "strings" "testing" @@ -561,6 +563,23 @@ func TestMuxServeHTTP(t *testing.T) { unescapingMode: runtime.UnescapingModeAllCharacters, respContent: "POST /api/v1/organizations:verb", }, + { + patterns: []stubPattern{ + { + method: "GET", + ops: []int{int(utilities.OpLitPush), 0, int(utilities.OpPush), 0, int(utilities.OpConcatN), 1}, + pool: []string{"foo", "id"}, + }, + }, + reqMethod: "GET", + reqPath: "/foo/%25", + headers: map[string]string{ + "Content-Type": "application/json", + }, + respStatus: http.StatusBadRequest, + unescapingMode: runtime.UnescapingModeAllExceptReserved, + respContent: `{"code":2,"message":"malformed path escape \"%\"","details":[]}`, + }, } { t.Run(strconv.Itoa(i), func(t *testing.T) { var opts []runtime.ServeMuxOption @@ -599,7 +618,13 @@ func TestMuxServeHTTP(t *testing.T) { t.Errorf("w.Code = %d; want %d; patterns=%v; req=%v", got, want, spec.patterns, r) } if spec.respContent != "" { - if got, want := w.Body.String(), spec.respContent; got != want { + got, want := w.Body.String(), spec.respContent + var gotJSON, wantJSON map[string]any + if json.Unmarshal([]byte(got), &gotJSON) == nil && json.Unmarshal([]byte(want), &wantJSON) == nil { + if !reflect.DeepEqual(gotJSON, wantJSON) { + t.Errorf("w.Body = %q; want %q; patterns=%v; req=%v", got, want, spec.patterns, r) + } + } else if got != want { t.Errorf("w.Body = %q; want %q; patterns=%v; req=%v", got, want, spec.patterns, r) } }