Skip to content

[Bug]: Invalid Query Param Values on MultiSelectFilter cause error #2033

@leesherwood

Description

@leesherwood

What happened?

TypeError is thrown if you pass an invalid value in the query parameter of a MultiSelectFilter

htmlspecialchars(): Argument #1 ($string) must be of type string, array given

How to reproduce the bug

Create a table with any MultiSelectFilter, such as:

MultiSelectFilter::make('Country')
                ->options(['uk' => 'United Kingdom', 'fr' => 'France', 'ge' => 'Germany'])

Enable the filter selecting only ONE value, then modify the URL query string to have an invalid filter value:

http://localhost/admin/testpage?table-filters[country][0]=no

Hit enter and the error will appear

Package Version

3.5.0

PHP Version

8.1.x

Laravel Version

11.10.0

Alpine Version

No response

Theme

Tailwind 3.x

Notes

When the filter values are passed through this function: https://github.com/rappasoft/laravel-livewire-tables/blob/master/src/Views/Filters/MultiSelectFilter.php#L37 , it returns an empty array as it correctly discards our edited invalid value.

This empty array is then output here: https://github.com/rappasoft/laravel-livewire-tables/blob/master/resources/views/components/tools/filter-pills.blade.php#L42

@if(is_array($filterPillValue) && !empty($filterPillValue))
    @foreach($filterPillValue as $filterPillArrayValue)
        {{ $filterPillArrayValue }}{!! $separator !!}
    @endforeach
@else
    {{ $filterPillValue }}
@endif

The first condition is false, so it drops into the else which is then running {{ [] }} or <?php echo e([]); ?>


The easiest fix is to remove the && !empty($filterPillValue) on the first condition. It will show the filter applied with no values, but better than an error and not entirely an unexpected result (I think this would be fine).

A "better" fix might be to disable the filter if there's no valid value post-sanitisation.

Error Message

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions