MCPcopy
hub / github.com/labstack/echo / TestRouterAnyMatchesLastAddedAnyRoute

Function TestRouterAnyMatchesLastAddedAnyRoute

router_test.go:1437–1460  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
1437func 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
1463func TestRouterMatchAnyPrefixIssue(t *testing.T) {

Callers

nothing calls this directly

Calls 6

PathMethod · 0.95
NewFunction · 0.85
NewContextMethod · 0.80
GetOrMethod · 0.80
RouteMethod · 0.65
GETMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…