-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Routing] added route compile check to identify a bad default value #5400
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
Conversation
…required variable that does not match the requirement
Commits ------- cb7e3f5 [Routing] added route compile check to identify a default value of a required variable that does not match the requirement Discussion ---------- [Routing] added route compile check to identify a bad default value BC break: yes but only for strange route definitions See the exception message in code for the reasoning. An exception is thrown for a __required__ variable that __has a default__ that __doesn't match__ the requirement. So optional variables can of course still have a default that don't meet the requirement, which is useful. This helps to identify useless route definitions at compile time instead of when generating or matching a URL.
Mmmm, i have this route
When the user doesn't choose any order, id is null and it displays the last one. With this PR this route is going to throw an Exception which is not very nice, i don't think the route is bad in any way. If the user doesn't chose any id, i want it to be null, not 0 or -1. In the docs example about routing the default for the blog page is set to 1, as this is always going te be the first page, but in my case, i do not know beforehand which is the last order id of the user, i need that param to be set to null. Can we reconsider this or at least, discuss it a little bit more? I don't think we should be BC breaking things in RC2, this kind of route is not that strange. The only option which i can think of is having 2 routes for the same controller action with different params
|
This is like Validation in forms. All validators accept the null value. Only when the value is not null then they validate it against the validation rules. I guess the behaviour should be the same. Maybe we could add an exception for the null value? |
+1 for allowing an null value |
@acasademont Your route with null as default is fine and shouldn't be influenced by this PR because |
Nope i couldn't try it yet, sorry. To my knowledge, all variables in the "requirements" section are not optional unless a "defaults" for that variable is set. I see from the code that the first optional variable is not checked agains the requirements regexp. If that is the case, all i said was wrong. |
I've just reverted this pull request as it introduces some regressions? It was a very bad idea to merge this so close to the release of 2.1 and I'm the one to blame. Sorry about that. @Tobion As apparently it is not possible to reopen a pull request, can you re-submit it again, so that it is not lost? Thanks and sorry again for the trouble. |
BC break: yes but only for strange route definitions
See the exception message in code for the reasoning.
An exception is thrown for a required variable that has a default that doesn't match the requirement.
So optional variables can of course still have a default that don't meet the requirement, which is useful.
This helps to identify useless route definitions at compile time instead of when generating or matching a URL.