Avoid passing null to array_filter in user controller

This commit is contained in:
Marcus Moore
2025-11-17 10:26:29 -08:00
parent bcd32da2bc
commit c36c8968d3
2 changed files with 15 additions and 0 deletions

View File

@@ -162,6 +162,11 @@ class UsersController extends Controller
if ($request->filled('filter')) {
$filter = json_decode($request->input('filter'), true);
if (is_null($filter)) {
$filter = [];
}
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
return in_array($key, $allowed_columns);
}, ARRAY_FILTER_USE_KEY);

View File

@@ -57,4 +57,14 @@ class IndexUsersTest extends TestCase
->etc();
});
}
public function test_gracefully_handles_malformed_filter()
{
$this->actingAsForApi(User::factory()->viewUsers()->create())
->getJson(route('api.users.index', [
// filter should be a json encoded array and not a string
'filter' => 'email:an-email-address@example.com',
]))
->assertOk();
}
}