You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If I append multiple middlewares to slices in this manner: middleware := append([]fiber.Handler{f, f}, f), and re-use this middleware for different routes (with different handlers), the routing won't work correctly but will always take the last registered endpoint.
How to Reproduce
Just run the example code below to start the faulty server.
Invoke http://localhost:12345/p1
You'll see "p2" printed, instead of "p1". Changing the p2 endpoint to the POST method won't change this faulty behavior either.
Remove any of the fs from the middleware, the expected "p1" willl be printed.
Expected Behavior
I'ld expect the proper route to be taken, i.e. "p1" being printed when I invoke the p1 endpoint.
@JonasDoeappend change the original array. That has nothing to do with our routing.
Woot, this would explain the bug, but would destroy my understanding of slices.
That said, I cannot reproduce this "changing of the original array": In this example, s1 remains unchanged - what am I missing?
Edit: Found an explanation. Basically, I was filling up the initial slices up to its capacity. Well, this is really stunning. Thanks for the heads up!
Bug Description
If I append multiple middlewares to slices in this manner:
middleware := append([]fiber.Handler{f, f}, f)
, and re-use thismiddleware
for different routes (with different handlers), the routing won't work correctly but will always take the last registered endpoint.How to Reproduce
http://localhost:12345/p1
"p2"
printed, instead of"p1"
. Changing thep2
endpoint to thePOST
method won't change this faulty behavior either.f
s from the middleware, the expected"p1"
willl be printed.Expected Behavior
I'ld expect the proper route to be taken, i.e.
"p1"
being printed when I invoke thep1
endpoint.Fiber Version
v2.52.4
v3.0.0-beta.2
Code Snippet (optional)
For
v2
:For
v3
:Checklist:
The text was updated successfully, but these errors were encountered: