Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Filters/SearchableFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function filter(RestifyRequest $request, $query, $value)
if (! config('restify.search.case_sensitive')) {
$upper = strtoupper($value);

return $query->orWhereRaw("UPPER({$this->column}) LIKE \"%{$upper}%\"");
return $query->orWhereRaw("UPPER({$this->column}) LIKE ?", ['%'.$upper.'%']);
}

return $query->orWhere($this->column, $likeOperator, "%{$value}%");
Expand Down
45 changes: 45 additions & 0 deletions tests/Feature/RepositorySearchServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,51 @@ public function test_can_search_using_belongs_to_field_with_custom_foreign_key()
->assertJsonCount(2, 'data');
}

public function test_can_search_strings_with_quotes_and_double_quotes(): void
{
Post::factory()->create([
'title' => "A Guy Named O'Neal was Standing at 5 o'clock with a 10\" cookie.",
]);

$this->getJson(PostRepository::route(query: ['search' => 'John']))
->assertJsonCount(0, 'data');

$this->getJson(PostRepository::route(query: ['search' => 'Guy']))
->assertJsonCount(1, 'data');

$this->getJson(PostRepository::route(query: ['search' => "5 o'clock"]))
->assertJsonCount(1, 'data');

$this->getJson(PostRepository::route(query: ['search' => '10" present']))
->assertJsonCount(0, 'data');

$this->getJson(PostRepository::route(query: ['search' => '10" cookie']))
->assertJsonCount(1, 'data');

$this->getJson(PostRepository::route(query: ['search' => '150TPL5 (1 1/2" PVC SCH40 THREADED PLUG']))
->assertJsonCount(0, 'data');

config()->set('restify.search.case_sensitive', false);

$this->getJson(PostRepository::route(query: ['search' => 'John']))
->assertJsonCount(0, 'data');

$this->getJson(PostRepository::route(query: ['search' => 'Guy']))
->assertJsonCount(1, 'data');

$this->getJson(PostRepository::route(query: ['search' => "5 o'clock"]))
->assertJsonCount(1, 'data');

$this->getJson(PostRepository::route(query: ['search' => '10" present']))
->assertJsonCount(0, 'data');

$this->getJson(PostRepository::route(query: ['search' => '10" cookie']))
->assertJsonCount(1, 'data');

$this->getJson(PostRepository::route(query: ['search' => '150TPL5 (1 1/2" PVC SCH40 THREADED PLUG']))
->assertJsonCount(0, 'data');
}

public function test_can_match_closure(): void
{
User::factory(4)->create();
Expand Down