Skip to content

Commit b6d2c6d

Browse files
authored
Merge pull request #18208 from marcusmoore/fixes/null-array-filter
Fixed potential exception while filtering in users index endpoint
2 parents bcd32da + c36c896 commit b6d2c6d

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

app/Http/Controllers/Api/UsersController.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,11 @@ public function index(Request $request) : array
162162

163163
if ($request->filled('filter')) {
164164
$filter = json_decode($request->input('filter'), true);
165+
166+
if (is_null($filter)) {
167+
$filter = [];
168+
}
169+
165170
$filter = array_filter($filter, function ($key) use ($allowed_columns) {
166171
return in_array($key, $allowed_columns);
167172
}, ARRAY_FILTER_USE_KEY);

tests/Feature/Users/Api/IndexUsersTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,14 @@ public function testReturnsManagedLocationsCountCorrectly()
5757
->etc();
5858
});
5959
}
60+
61+
public function test_gracefully_handles_malformed_filter()
62+
{
63+
$this->actingAsForApi(User::factory()->viewUsers()->create())
64+
->getJson(route('api.users.index', [
65+
// filter should be a json encoded array and not a string
66+
'filter' => 'email:[email protected]',
67+
]))
68+
->assertOk();
69+
}
6070
}

0 commit comments

Comments
 (0)