NOTE: this is to document current implementation. Last added route with `*` asterisk is always the match and no backtracking or more precise matching is done to find more suitable match. Current behaviour might not be correct or expected. But this is where we are without well defined requirements/r
(t *testing.T)
| 1435 | // Current behaviour might not be correct or expected. |
| 1436 | // But this is where we are without well defined requirements/rules how (multiple) asterisks work in route |
| 1437 | func TestRouterAnyMatchesLastAddedAnyRoute(t *testing.T) { |
| 1438 | e := New() |
| 1439 | |
| 1440 | e.GET("/users/*", handlerFunc) |
| 1441 | e.GET("/users/*/action*", handlerFunc) |
| 1442 | |
| 1443 | req := httptest.NewRequest(http.MethodGet, "/users/xxx/action/sea", nil) |
| 1444 | c := e.NewContext(req, nil) |
| 1445 | handler := e.router.Route(c) |
| 1446 | |
| 1447 | assert.NoError(t, handler(c)) |
| 1448 | assert.Equal(t, "/users/*/action*", c.Path()) |
| 1449 | assert.Equal(t, "xxx/action/sea", c.pathValues.GetOr("*", "")) |
| 1450 | |
| 1451 | // if we add another route then it is the last added and so it is matched |
| 1452 | e.GET("/users/*/action/search", handlerFunc) |
| 1453 | |
| 1454 | c2 := e.NewContext(httptest.NewRequest(http.MethodGet, "/users/xxx/action/sea", nil), nil) |
| 1455 | handler2 := e.router.Route(c2) |
| 1456 | |
| 1457 | assert.NoError(t, handler2(c2)) |
| 1458 | assert.Equal(t, "/users/*/action/search", c2.Path()) |
| 1459 | assert.Equal(t, "xxx/action/sea", c2.pathValues.GetOr("*", "")) |
| 1460 | } |
| 1461 | |
| 1462 | // Issue #1739 |
| 1463 | func TestRouterMatchAnyPrefixIssue(t *testing.T) { |