From bfe56d7a31bfc68fe2f71ed1b945d3a4d9663383 Mon Sep 17 00:00:00 2001 From: mikestefanello Date: Fri, 8 Jul 2022 09:58:42 -0400 Subject: [PATCH] Fix incorrect params when building controller redirect route url. --- controller/controller.go | 2 +- controller/controller_test.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/controller/controller.go b/controller/controller.go index 539ce97..1035bce 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -152,7 +152,7 @@ func (c *Controller) cachePage(ctx echo.Context, page Page, html *bytes.Buffer) // Redirect redirects to a given route name with optional route parameters func (c *Controller) Redirect(ctx echo.Context, route string, routeParams ...interface{}) error { - url := ctx.Echo().Reverse(route, routeParams) + url := ctx.Echo().Reverse(route, routeParams...) if htmx.GetRequest(ctx).Boosted { htmx.Response{ diff --git a/controller/controller_test.go b/controller/controller_test.go index a9d0e28..0ec1727 100644 --- a/controller/controller_test.go +++ b/controller/controller_test.go @@ -43,11 +43,15 @@ func TestMain(m *testing.M) { } func TestController_Redirect(t *testing.T) { + c.Web.GET("/path/:first/and/:second", func(c echo.Context) error { + return nil + }).Name = "redirect-test" + ctx, _ := tests.NewContext(c.Web, "/abc") ctr := NewController(c) - err := ctr.Redirect(ctx, "home") + err := ctr.Redirect(ctx, "redirect-test", "one", "two") require.NoError(t, err) - assert.Equal(t, "", ctx.Response().Header().Get(echo.HeaderLocation)) + assert.Equal(t, "/path/one/and/two", ctx.Response().Header().Get(echo.HeaderLocation)) assert.Equal(t, http.StatusFound, ctx.Response().Status) }