Commit 592894a
committed
fix(routes): take a route's handler from the last argument, not the first
Express, Fastify, gin and Laravel all put middleware between the route
path and the handler, and the handler comes last:
routerGet("/users", requireAuth, rateLimit, listUsers);
extract_handler_arg returned the FIRST argument that looked like a
function reference, so requireAuth won and the HANDLES edge pointed at
the middleware instead of listUsers. That is a wrong edge, not a
missing one, and it misleads anyone tracing a request through the
graph.
The scan bound hid a second fault. An arrow function matches none of
the accepted node kinds, so three inline middlewares pushed the real
handler past MAX_HANDLER_SCAN and no handler came back at all.
The loop now examines every argument and keeps the last eligible one.
Nothing that follows a handler matches the accepted kinds either, since
an options argument is an object node, so the last match is the
handler. HANDLER_START_IDX stays, because argument 0 really is the
path. MAX_HANDLER_SCAN had no other use and is gone.
A two-argument route has one eligible argument, so first and last agree
and the existing Express, Fastify, gin and Laravel route tests are
unchanged.
Both tests fail without the change, the first reporting "requireAuth"
where "listUsers" belongs and the second reporting no handler at all.
Signed-off-by: Joshua Richter <jrichter5781@gmail.com>1 parent 5fbab7b commit 592894a
2 files changed
Lines changed: 59 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
25 | | - | |
26 | 24 | | |
27 | 25 | | |
28 | 26 | | |
| |||
2349 | 2347 | | |
2350 | 2348 | | |
2351 | 2349 | | |
| 2350 | + | |
| 2351 | + | |
| 2352 | + | |
| 2353 | + | |
| 2354 | + | |
| 2355 | + | |
| 2356 | + | |
| 2357 | + | |
| 2358 | + | |
2352 | 2359 | | |
2353 | | - | |
| 2360 | + | |
2354 | 2361 | | |
2355 | 2362 | | |
2356 | 2363 | | |
| |||
2362 | 2369 | | |
2363 | 2370 | | |
2364 | 2371 | | |
2365 | | - | |
| 2372 | + | |
| 2373 | + | |
2366 | 2374 | | |
2367 | 2375 | | |
2368 | 2376 | | |
2369 | 2377 | | |
2370 | 2378 | | |
2371 | | - | |
| 2379 | + | |
2372 | 2380 | | |
2373 | 2381 | | |
2374 | 2382 | | |
2375 | | - | |
| 2383 | + | |
2376 | 2384 | | |
2377 | 2385 | | |
2378 | 2386 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3970 | 3970 | | |
3971 | 3971 | | |
3972 | 3972 | | |
| 3973 | + | |
| 3974 | + | |
| 3975 | + | |
| 3976 | + | |
| 3977 | + | |
| 3978 | + | |
| 3979 | + | |
| 3980 | + | |
| 3981 | + | |
| 3982 | + | |
| 3983 | + | |
| 3984 | + | |
| 3985 | + | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
| 3996 | + | |
| 3997 | + | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
| 4004 | + | |
| 4005 | + | |
| 4006 | + | |
| 4007 | + | |
| 4008 | + | |
| 4009 | + | |
| 4010 | + | |
| 4011 | + | |
| 4012 | + | |
| 4013 | + | |
| 4014 | + | |
| 4015 | + | |
3973 | 4016 | | |
3974 | 4017 | | |
3975 | 4018 | | |
| |||
6812 | 6855 | | |
6813 | 6856 | | |
6814 | 6857 | | |
| 6858 | + | |
| 6859 | + | |
6815 | 6860 | | |
6816 | 6861 | | |
6817 | 6862 | | |
| |||
0 commit comments