From 628a2df08cc5bf6b8e9036b4c08ccd02bdf53da7 Mon Sep 17 00:00:00 2001 From: toimtoimtoim Date: Thu, 17 Dec 2020 02:01:57 +0200 Subject: [PATCH 1/3] Revert "Add a test" This reverts commit 7a1126fb --- group_test.go | 34 ---------------------------------- 1 file changed, 34 deletions(-) diff --git a/group_test.go b/group_test.go index d4a6846f5..c51fd91eb 100644 --- a/group_test.go +++ b/group_test.go @@ -119,37 +119,3 @@ func TestGroupRouteMiddlewareWithMatchAny(t *testing.T) { assert.Equal(t, "/*", m) } - -func TestMultipleGroupSamePathMiddleware(t *testing.T) { - // Ensure multiple groups with the same path do not clobber previous routes or mixup middlewares - e := New() - m1 := func(next HandlerFunc) HandlerFunc { - return func(c Context) error { - c.Set("middleware", "m1") - return next(c) - } - } - m2 := func(next HandlerFunc) HandlerFunc { - return func(c Context) error { - c.Set("middleware", "m2") - return next(c) - } - } - h := func(c Context) error { - return c.String(http.StatusOK, c.Get("middleware").(string)) - } - - g1 := e.Group("/group", m1) - { - g1.GET("", h) - } - g2 := e.Group("/group", m2) - { - g2.GET("/other", h) - } - - _, m := request(http.MethodGet, "/group", e) - assert.Equal(t, "m1", m) - _, m = request(http.MethodGet, "/group/other", e) - assert.Equal(t, "m2", m) -} From 655596b1b9312274c18b9fbbeb61fa51a2c5c39f Mon Sep 17 00:00:00 2001 From: toimtoimtoim Date: Thu, 17 Dec 2020 02:01:59 +0200 Subject: [PATCH 2/3] Revert "Remove group.Use registering Any routes that break other routes" This reverts commit f72eaa42 --- group.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/group.go b/group.go index d239fb581..426bef9eb 100644 --- a/group.go +++ b/group.go @@ -23,6 +23,10 @@ func (g *Group) Use(middleware ...MiddlewareFunc) { if len(g.middleware) == 0 { return } + // Allow all requests to reach the group as they might get dropped if router + // doesn't find a match, making none of the group middleware process. + g.Any("", NotFoundHandler) + g.Any("/*", NotFoundHandler) } // CONNECT implements `Echo#CONNECT()` for sub-routes within the Group. From 547ca5ca1e49e1dc24f73ab446fc738c2a636301 Mon Sep 17 00:00:00 2001 From: toimtoimtoim Date: Thu, 17 Dec 2020 02:20:26 +0200 Subject: [PATCH 3/3] reverts #1671 changes --- echo.go | 1 - echo_test.go | 43 ------------------------------------------- 2 files changed, 44 deletions(-) diff --git a/echo.go b/echo.go index 4b0c785a5..d284ff396 100644 --- a/echo.go +++ b/echo.go @@ -500,7 +500,6 @@ func (common) static(prefix, root string, get func(string, HandlerFunc, ...Middl } return c.File(name) } - get(prefix, h) if prefix == "/" { return get(prefix+"*", h) } diff --git a/echo_test.go b/echo_test.go index 895ea1825..a6071e12a 100644 --- a/echo_test.go +++ b/echo_test.go @@ -102,15 +102,6 @@ func TestEchoStatic(t *testing.T) { expectHeaderLocation: "/folder/", expectBodyStartsWith: "", }, - { - name: "Directory Redirect with non-root path", - givenPrefix: "/static", - givenRoot: "_fixture", - whenURL: "/static", - expectStatus: http.StatusMovedPermanently, - expectHeaderLocation: "/static/", - expectBodyStartsWith: "", - }, { name: "Directory with index.html", givenPrefix: "/", @@ -170,40 +161,6 @@ func TestEchoStatic(t *testing.T) { } } -func TestEchoStaticRedirectIndex(t *testing.T) { - assert := assert.New(t) - e := New() - - // HandlerFunc - e.Static("/static", "_fixture") - - errCh := make(chan error) - - go func() { - errCh <- e.Start("127.0.0.1:1323") - }() - - time.Sleep(200 * time.Millisecond) - - if resp, err := http.Get("http://127.0.0.1:1323/static"); err == nil { - defer resp.Body.Close() - assert.Equal(http.StatusOK, resp.StatusCode) - - if body, err := ioutil.ReadAll(resp.Body); err == nil { - assert.Equal(true, strings.HasPrefix(string(body), "")) - } else { - assert.Fail(err.Error()) - } - - } else { - assert.Fail(err.Error()) - } - - if err := e.Close(); err != nil { - t.Fatal(err) - } -} - func TestEchoFile(t *testing.T) { e := New() e.File("/walle", "_fixture/images/walle.png")