Issue #1754 - router needs to backtrack multiple levels upwards in tree to find the matching route route evaluation order Request for "/a/c/f" should match "/:e/c/f" +-0,7--------+ | "/" (root) |----------------------------------+
(t *testing.T)
| 1136 | // | "/c" (static) | |
| 1137 | // +---------------+ |
| 1138 | func TestRouteMultiLevelBacktracking2(t *testing.T) { |
| 1139 | e := New() |
| 1140 | |
| 1141 | e.GET("/a/:b/c", handlerFunc) |
| 1142 | e.GET("/a/c/d", handlerFunc) |
| 1143 | e.GET("/a/c/df", handlerFunc) |
| 1144 | e.GET("/:e/c/f", handlerFunc) |
| 1145 | e.GET("/*", handlerFunc) |
| 1146 | |
| 1147 | var testCases = []struct { |
| 1148 | expectParam map[string]string |
| 1149 | name string |
| 1150 | whenURL string |
| 1151 | expectRoute string |
| 1152 | }{ |
| 1153 | { |
| 1154 | name: "route /a/c/df to /a/c/df", |
| 1155 | whenURL: "/a/c/df", |
| 1156 | expectRoute: "/a/c/df", |
| 1157 | }, |
| 1158 | { |
| 1159 | name: "route /a/x/df to /a/:b/c", |
| 1160 | whenURL: "/a/x/c", |
| 1161 | expectRoute: "/a/:b/c", |
| 1162 | expectParam: map[string]string{"b": "x"}, |
| 1163 | }, |
| 1164 | { |
| 1165 | name: "route /a/c/f to /:e/c/f", |
| 1166 | whenURL: "/a/c/f", |
| 1167 | expectRoute: "/:e/c/f", |
| 1168 | expectParam: map[string]string{"e": "a"}, |
| 1169 | }, |
| 1170 | { |
| 1171 | name: "route /b/c/f to /:e/c/f", |
| 1172 | whenURL: "/b/c/f", |
| 1173 | expectRoute: "/:e/c/f", |
| 1174 | expectParam: map[string]string{"e": "b"}, |
| 1175 | }, |
| 1176 | { |
| 1177 | name: "route /b/c/c to /*", |
| 1178 | whenURL: "/b/c/c", |
| 1179 | expectRoute: "/*", |
| 1180 | expectParam: map[string]string{"*": "b/c/c"}, |
| 1181 | }, |
| 1182 | { // this traverses `/a/:b/c` and `/:e/c/f` branches and eventually backtracks to `/*` |
| 1183 | name: "route /a/c/cf to /*", |
| 1184 | whenURL: "/a/c/cf", |
| 1185 | expectRoute: "/*", |
| 1186 | expectParam: map[string]string{"*": "a/c/cf"}, |
| 1187 | }, |
| 1188 | { |
| 1189 | name: "route /anyMatch to /*", |
| 1190 | whenURL: "/anyMatch", |
| 1191 | expectRoute: "/*", |
| 1192 | expectParam: map[string]string{"*": "anyMatch"}, |
| 1193 | }, |
| 1194 | { |
| 1195 | name: "route /anyMatch/withSlash to /*", |
nothing calls this directly
no test coverage detected
searching dependent graphs…