Skip to content

fix(laravel): ignore invalid range filter values - #8632

Open
NotAFlightRisk wants to merge 3 commits into
api-platform:4.4from
NotAFlightRisk:fix/laravel-range-filter-invalid-value
Open

NotAFlightRisk wants to merge 3 commits into
api-platform:4.4from
NotAFlightRisk:fix/laravel-range-filter-invalid-value

Conversation

@NotAFlightRisk

Copy link
Copy Markdown
Contributor
Q A
Branch? 4.4
Tickets none, didn't think it needed one
License MIT
Doc PR -

The Laravel RangeFilter now ignores values it can't use, rather than throwing a 500. On the workbench app /api/books?isbn_range=5 was failing with foreach() argument must be of type array|object, string given, and ?isbn_range[unknown]=5 with Undefined array key "unknown".

Theyre both pretty easy for a client to get wrong, eihter by leaving the operator off or misspelling it. Both come back 200 with the unfiltered list now.

public function apply(Builder $builder, mixed $values, Parameter $parameter, array $context = []): Builder
{
if (!\is_array($values)) {
return $builder;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we add a log like we do in other filters so that a user can debug this ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cheers @soyuka, done. I'd only compared it with the other Laravel filters, and none of those log, so I never looked at how the Doctrine range filter handles it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants