Skip to content

[HttpFoundation] Avoid Bad Request exceptions when getting query parameters with default values #54208

@javiereguiluz

Description

@javiereguiluz

Description

If you have this code:

$page = $request->query->getInt('page', 1);

If someone mangles with the URL param and passes e.g. ?page=foobar you'll see this exception:

HTTP 400 Bad Request
Input value "page" is invalid and flag "FILTER_NULL_ON_FAILURE" was not set.

Would it make sense for getInt() (and similar methods) to just return the default value (1) that you defined?

Thanks

Example

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions