Fixed RB-4136 - array to string conversion when people throw random crap at the API
This commit is contained in:
@@ -53,7 +53,7 @@ trait Searchable
|
||||
*/
|
||||
public function scopeTextSearch($query, $search)
|
||||
{
|
||||
$preparedSearch = $this->prepareSearchInput((string) $search);
|
||||
$preparedSearch = $this->prepareSearchInput(is_array($search) ? implode(' ', $search) : (string) $search);
|
||||
$terms = $preparedSearch['terms'];
|
||||
$filters = $preparedSearch['filters'];
|
||||
$filterOperator = $preparedSearch['filter_operator'];
|
||||
|
||||
@@ -572,6 +572,27 @@ class SearchableTraitTest extends TestCase
|
||||
->assertJson(fn (AssertableJson $json) => $json->has('rows', 3)->etc());
|
||||
}
|
||||
|
||||
/**
|
||||
* Regression: passing search as an array (?search[]=foo) must not throw
|
||||
* "Array to string conversion" — values should be joined and searched normally.
|
||||
*/
|
||||
public function test_array_search_param_does_not_throw()
|
||||
{
|
||||
Asset::factory()->create(['name' => 'ArraySearchMacBook']);
|
||||
Asset::factory()->create(['name' => 'ArraySearchDell']);
|
||||
|
||||
// search[]=ArraySearchMacBook simulates ?search[]=ArraySearchMacBook in the URL
|
||||
$this->actingAsForApi(User::factory()->viewAssets()->create())
|
||||
->getJson(route('api.assets.index', ['search' => ['ArraySearchMacBook']]))
|
||||
->assertOk()
|
||||
->assertJson(fn (AssertableJson $json) => $json->has('rows', 1)->etc());
|
||||
|
||||
// Multiple array values must not throw — exact match count depends on join semantics
|
||||
$this->actingAsForApi(User::factory()->viewAssets()->create())
|
||||
->getJson(route('api.assets.index', ['search' => ['ArraySearchMacBook', 'ArraySearchDell']]))
|
||||
->assertOk();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test no results when search matches nothing
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user