mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
Merge pull request #16865 from Capevace/3.x
Fix SQL syntax error during global search when using : in table names #16864
This commit is contained in:
@@ -163,22 +163,25 @@ if (! function_exists('Filament\Support\generate_search_column_expression')) {
|
||||
{
|
||||
$driverName = $databaseConnection->getDriverName();
|
||||
|
||||
if (Str::lower($column) !== $column) {
|
||||
$column = match ($driverName) {
|
||||
'pgsql' => (string) str($column)->wrap('"'),
|
||||
default => $column,
|
||||
};
|
||||
}
|
||||
|
||||
$column = match ($driverName) {
|
||||
'pgsql' => (str($column)->contains('->')
|
||||
? str($column)
|
||||
->beforeLast('->')
|
||||
'pgsql' => (
|
||||
str($column)->contains('->')
|
||||
? str(
|
||||
str($column)
|
||||
->beforeLast('->')
|
||||
->explode('.')
|
||||
->map(fn (string $part) => str($part)->wrap('"'))
|
||||
->implode('.')
|
||||
)
|
||||
->append('->>')
|
||||
->append("'")
|
||||
->append(str($column)->afterLast('->'))
|
||||
->append("'")
|
||||
: $column) . '::text',
|
||||
: str($column)
|
||||
->explode('.')
|
||||
->map(fn (string $part) => str($part)->wrap('"'))
|
||||
->implode('.')
|
||||
) . '::text',
|
||||
default => $column,
|
||||
};
|
||||
|
||||
|
||||
@@ -75,5 +75,24 @@ it('will generate json search column expression for pgsql', function () {
|
||||
$expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection);
|
||||
|
||||
expect($expression->getValue($grammar))
|
||||
->toBe("lower(data->>'name'::text)");
|
||||
->toBe("lower(\"data\"->>'name'::text)");
|
||||
});
|
||||
|
||||
it('will generate column expression for pgsql with colons in the name', function (string $column, string $text) {
|
||||
$isSearchForcedCaseInsensitive = true;
|
||||
|
||||
$databaseConnection = Mockery::mock(Connection::class);
|
||||
$databaseConnection->shouldReceive('getDriverName')->andReturn('pgsql');
|
||||
$databaseConnection->shouldReceive('getConfig')->with('search_collation')->andReturn(null);
|
||||
|
||||
$grammar = new PostgresGrammar($databaseConnection);
|
||||
|
||||
$expression = generate_search_column_expression($column, $isSearchForcedCaseInsensitive, $databaseConnection);
|
||||
|
||||
expect($expression->getValue($grammar))
|
||||
->toBe($text);
|
||||
})
|
||||
->with([
|
||||
['blog:posts.title', 'lower("blog:posts"."title"::text)'],
|
||||
['blog:posts:comments.author.name', 'lower("blog:posts:comments"."author"."name"::text)'],
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user