-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[HttpKernel] Prevent TypeError for out-of-range route parameters #61458
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
base: 7.4
Are you sure you want to change the base?
[HttpKernel] Prevent TypeError for out-of-range route parameters #61458
Conversation
…RequestAttributeScalarValueResolver - Added RequestAttributeScalarValueResolver to safely resolve typed scalar arguments and throw 404 on invalid input - Registered resolver with high priority before raw attribute resolver - Added unit and functional tests for int route param edge cases - Documented behavior in Routing CHANGELOG
Hey! I see that this is your first PR. That is great! Welcome! Symfony has a contribution guide which I suggest you to read. In short:
Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change. When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor! I am going to sit back now and wait for the reviews. Cheers! Carsonbot |
src/Symfony/Component/HttpKernel/Controller/ArgumentResolver.php
Outdated
Show resolved
Hide resolved
...ony/Component/HttpKernel/Controller/ArgumentResolver/RequestAttributeScalarValueResolver.php
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For enums, this looks already covered by BackedEnumValueResolver
For other scalar types, I'd suggest implementing this in RequestAttributeValueResolver
Btw, the implementation in RequestAttributeValueResolver should probably use the right getter of the ParameterBag instead of reimplementing the conversion logic in the value resolver after using |
…questAttributeValueResolver
This PR fixes issue #61451 by introducing a new
RequestAttributeScalarValueResolver
that safely casts request attributes (route parameters) to scalar types (int, float, bool, string, or \BackedEnum).If a value cannot be safely cast (e.g.
9223372036854775808
for anint
), aNotFoundHttpException
(404) is thrown before reaching the controller, avoiding aTypeError
.Changes:
RequestAttributeScalarValueResolver
(registered with high priority)/{id}
route expectingint $id
CHANGELOG.md
entry under 7.4This makes route handling safer and more predictable for typed controllers.