New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
anything and parameter should be the same node #91
Comments
It feels like this is a bug, or at least some undocumented behavior. The docs suggest that this is how
On the contrary, these routes fail if you do the following, which feels unintuitive for the reasons @stevapple mentions because the second route shouldn't have to care that the first has named a wildcard parameter that it doesn't care about.
I've got some work that may solve this problem over in a fork that I'm happy to open as a PR if it's decided that this is something worth updating. |
@maciesielka I'm assuming that the |
@0xTim Yup. That's exactly the problem. The second route handler is required to use |
@maciesielka what would you propose the solution be? You're registering the same route with two different handlers which is ambiguous at best. Out of curiosity does Vapor print out a warning saying that the route is overridden? Because outside of that I'm not sure what else we could efficiently do. Checking a route handler doesn't care about a parameter is hard because we'd have to run the whole route handler to make sure it doesn't use it anywhere before trying another one, which is obviously inefficient |
@0xTim Hmm I wonder if my choice of example has added to some confusion. Let me try again:
I think the API seems to signal that I'm registering two different handlers, and the latter is breaking because I lacked knowledge of the first. The real life example here is that my app already registered many handlers using I think one solution without sacrificing efficiency is exactly like the OP mentions: treat |
To answer your question, though, there isn't a warning about this case. In order to get my old handlers to fire alongside my new one, I added the named parameter to all my old handlers by trial and error. |
Right sorry, I misread your issue (I read it as I agree that I think a PR as you have it is worthwhile. I will warn you in advance that any changes to the |
Haha apologies for the poor |
In the current Trie tree,
anything
(aka.*
) andparameter
(aka.:name
) are treated as different nodes, while the latter has a higher priority. However, they have exactly the same matching strategy and behavior, except thatparameter
will set a parameter whileanything
doesn’t have one.Shouldn’t they be treated the same as routes like
test/*
andtest/:name
matches exactly the same cases?Possible solution: treat
.anything
as.parameter("")
and unsetparameters[""]
after matching completed.The text was updated successfully, but these errors were encountered: