-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Form rendering throws notice if the form is submitted with array instead of string #23995
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
Comments
So that means the page would result in a 500 error because the user is messing with the HTML? |
No, I jumped to conclusion too fast. It only reports a notice. Which is converted to exception in In It happens also on the Symfony.com: http://symfony.com/search?q[foo]=form. But if the developer forgets to add (I checked several webapps and most of them are prone to this issue) |
I'm not entirely sure how we can fix this this properly, we could add a safe guard in the themes (which will not fix this issue for custom themes). Or we can add a transformer to ensure if a none scalar value is provided it's transformed to an empty string. But this could be considered a BC break as some may have added additional transformer(s) that expect this kind of behavior 🤔 |
@iltar I'm afraid I found a case when it fails with 500. Can someone please check that I haven't overlooked something? When there is another assert - such as if (!is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) {
throw new UnexpectedTypeException($value, 'string');
} So if the The
Case for reproduction (you need to change input name from public function createyAction(Request $request)
{
$form = $this->createFormBuilder()
->add('title', TextType::class, [
'constraints' => [
new Type('string'),
new Length(['min' => 10]),
],
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
//foo
}
return $this->render('article/add-article.html.twig', [
'form' => $form->createView(),
]);
} # article/add-article.html.twig
{% block body %}
{{ form(form) }}
{% endblock %} |
Honestly, if a user messes with the input fields, a 500 is justified. Won't have to expect valid responses if you send invalid requests |
For me it seems unexpected from the DX point-of-view: If the proper And I think it may be possible to flood the server logs with this error. |
@iltar you can not justify error 500 for unhandled user input validation (error 400 bad request would be more suitable in this case - yet still embarrassing for simple form validation) |
HTTP 400 (Bad Request) is for client errors, so it's inappropriate to return 500 Our logs are being filled with exceptions which don't need to be thrown |
Related #4102 |
closing in favour of #4102 |
When the user uses Chrome Inspect feature and changes the
<input type="text"
name to include an extra array (e.g. fromarticle_form[title]
toarticle_form[title][foobar]
, the form fails to render. The reason is that the template is trying to render the "invalid" array as an<input>
value.The problematic line in the template is this:
symfony/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig
Line 13 in 3a9653d
The simplest repro-case I managed to create is this one:
The text was updated successfully, but these errors were encountered: