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:
Dan Harrin
2025-07-08 14:24:08 +01:00
committed by GitHub
2 changed files with 34 additions and 12 deletions
+14 -11
View File
@@ -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,
};
+20 -1
View File
@@ -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)'],
]);