File tree Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Expand file tree Collapse file tree 2 files changed +34
-4
lines changed Original file line number Diff line number Diff line change @@ -23,10 +23,6 @@ func (g *Group) Use(middleware ...MiddlewareFunc) {
23
23
if len (g .middleware ) == 0 {
24
24
return
25
25
}
26
- // Allow all requests to reach the group as they might get dropped if router
27
- // doesn't find a match, making none of the group middleware process.
28
- g .Any ("" , NotFoundHandler )
29
- g .Any ("/*" , NotFoundHandler )
30
26
}
31
27
32
28
// CONNECT implements `Echo#CONNECT()` for sub-routes within the Group.
Original file line number Diff line number Diff line change @@ -119,3 +119,37 @@ func TestGroupRouteMiddlewareWithMatchAny(t *testing.T) {
119
119
assert .Equal (t , "/*" , m )
120
120
121
121
}
122
+
123
+ func TestMultipleGroupSamePathMiddleware (t * testing.T ) {
124
+ // Ensure multiple groups with the same path do not clobber previous routes or mixup middlewares
125
+ e := New ()
126
+ m1 := func (next HandlerFunc ) HandlerFunc {
127
+ return func (c Context ) error {
128
+ c .Set ("middleware" , "m1" )
129
+ return next (c )
130
+ }
131
+ }
132
+ m2 := func (next HandlerFunc ) HandlerFunc {
133
+ return func (c Context ) error {
134
+ c .Set ("middleware" , "m2" )
135
+ return next (c )
136
+ }
137
+ }
138
+ h := func (c Context ) error {
139
+ return c .String (http .StatusOK , c .Get ("middleware" ).(string ))
140
+ }
141
+
142
+ g1 := e .Group ("/group" , m1 )
143
+ {
144
+ g1 .GET ("" , h )
145
+ }
146
+ g2 := e .Group ("/group" , m2 )
147
+ {
148
+ g2 .GET ("/other" , h )
149
+ }
150
+
151
+ _ , m := request (http .MethodGet , "/group" , e )
152
+ assert .Equal (t , "m1" , m )
153
+ _ , m = request (http .MethodGet , "/group/other" , e )
154
+ assert .Equal (t , "m2" , m )
155
+ }
You can’t perform that action at this time.
0 commit comments