-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Description
Description
We've noticed some exceptions caused by wrong urls where instead of ?query_param=value
the user opened ?query_param[]=value
. This causes a BadRequestException
to be thrown: https://github.com/symfony/symfony/blob/7.4/src/Symfony/Component/HttpFoundation/InputBag.php#L40
We fixed this by using
{{ 'q' in app.request.query.all()|keys and app.request.query.all()['q'] is not iterable ? app.request.query.get('q') : '' }}
instead of a simple {{ app.request.query.get('q') }}
(which we used before).
I've looked into the class methods of Symfony\Component\HttpFoundation\InputBag
(which is used by $request->query
) and the inherited Symfony\Component\HttpFoundation\ParameterBag
and there doesn't seem to be a simple way to figure out if the value is scalar or non-scalar.
So I would like to open a discussion how we can address this.
Two ideas:
- A) add an additional
getValue(string $key, mixed $default = null): array|string|int|float|bool|null
method that also returns an array value - B) add a method
isScalar(string $key): bool
so you can check in an easier way what the value is
Example
If you use a simple
$request->query->get('q');
or in Twig
{{ app.request.query.get('q') }}
open the page that calls this code adding ?q[]=x
to the url.