Skip to content

Commit bc2daf1

Browse files
Removed explicit escaping for pgsql driver in FilterPartial#maybeSpecifyEscapeChar. Fixes #941 (#968)
* Fix styling * Removed explicit escaping for pgsql driver in FilterPartial#maybeSpecifyEscapeChar. Fixes #941 Added mariadb driver in FilterPartial#maybeSpecifyEscapeChar phpdoc for param $driver. Also adjusted test in order to run with mariadb driver only if the installed version of illuminate/database dependency supports the driver. * Fix styling --------- Co-authored-by: Talpx1 <[email protected]> Co-authored-by: Alex Vanderbist <[email protected]>
1 parent 46018b3 commit bc2daf1

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Filters/FiltersPartial.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ protected static function escapeLike(string $value): string
6969
}
7070

7171
/**
72-
* @param 'sqlite'|'pgsql'|'sqlsrc'|'mysql' $driver
72+
* @param 'sqlite'|'pgsql'|'sqlsrc'|'mysql'|'mariadb' $driver
7373
* @return string
7474
*/
7575
protected static function maybeSpecifyEscapeChar(string $driver): string
7676
{
77-
if (! in_array($driver, ['sqlite','pgsql','sqlsrv'])) {
77+
if (! in_array($driver, ['sqlite','sqlsrv'])) {
7878
return '';
7979
}
8080

tests/FilterTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@
9292
});
9393

9494
it('specifies escape character in supported databases', function (string $dbDriver) {
95+
if ($dbDriver === 'mariadb' && ! in_array('mariadb', DB::supportedDrivers())) {
96+
$this->markTestSkipped('mariadb driver not supported in the installed version of illuminate/database dependency');
97+
}
98+
9599
$fakeConnection = "test_{$dbDriver}";
96100

97101
DB::connectUsing($fakeConnection, [
@@ -100,6 +104,7 @@
100104
]);
101105

102106
DB::usingConnection($fakeConnection, function () use ($dbDriver) {
107+
103108
$request = new Request([
104109
'filter' => ['name' => 'to_find'],
105110
]);
@@ -108,10 +113,10 @@
108113
->allowedFilters('name', 'id')
109114
->toSql();
110115

111-
expect($queryBuilderSql)->when(in_array($dbDriver, ["sqlite","pgsql","sqlsrv"]), fn (Expectation $query) => $query->toContain("ESCAPE '\'"));
112-
expect($queryBuilderSql)->when($dbDriver === 'mysql', fn (Expectation $query) => $query->not->toContain("ESCAPE '\'"));
116+
expect($queryBuilderSql)->when(in_array($dbDriver, ["sqlite","sqlsrv"]), fn (Expectation $query) => $query->toContain("ESCAPE '\'"));
117+
expect($queryBuilderSql)->when(in_array($dbDriver, ["mysql","mariadb", "pgsql"]), fn (Expectation $query) => $query->not->toContain("ESCAPE '\'"));
113118
});
114-
})->with(['sqlite', 'mysql', 'pgsql', 'sqlsrv']);
119+
})->with(['sqlite', 'mysql', 'pgsql', 'sqlsrv', 'mariadb']);
115120

116121
it('can filter results based on the existence of a property in an array', function () {
117122
$results = createQueryFromFilterRequest([

0 commit comments

Comments
 (0)