Skip to content

Commit 80cdd87

Browse files
authored
[10.x] Fixes whereDate, whereDay, whereMonth, whereTime, whereYear and whereJsonLength to ignore invalid $operator (#52704)
* Fixes `whereDate`, `whereDay`, `whereMonth`, `whereTime`, `whereYear` and `whereJsonLength` to ignore invalid `$operator` Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> * wip Signed-off-by: Mior Muhammad Zaki <[email protected]> --------- Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent 05a9554 commit 80cdd87

File tree

3 files changed

+258
-2
lines changed

3 files changed

+258
-2
lines changed

src/Illuminate/Database/DBAL/TimestampType.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44

55
use Doctrine\DBAL\Exception as DBALException;
66
use Doctrine\DBAL\Platforms\AbstractPlatform;
7+
use Doctrine\DBAL\Platforms\MariaDb1010Platform;
78
use Doctrine\DBAL\Platforms\MariaDb1027Platform;
89
use Doctrine\DBAL\Platforms\MariaDb1052Platform;
910
use Doctrine\DBAL\Platforms\MariaDb1060Platform;
1011
use Doctrine\DBAL\Platforms\MariaDBPlatform;
1112
use Doctrine\DBAL\Platforms\MySQL57Platform;
1213
use Doctrine\DBAL\Platforms\MySQL80Platform;
14+
use Doctrine\DBAL\Platforms\MySQL84Platform;
1315
use Doctrine\DBAL\Platforms\MySQLPlatform;
1416
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
17+
use Doctrine\DBAL\Platforms\PostgreSQL120Platform;
1518
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
1619
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
1720
use Doctrine\DBAL\Platforms\SqlitePlatform;
@@ -33,13 +36,16 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform): st
3336
MySQLPlatform::class,
3437
MySQL57Platform::class,
3538
MySQL80Platform::class,
39+
MySQL84Platform::class,
3640
MariaDBPlatform::class,
3741
MariaDb1027Platform::class,
3842
MariaDb1052Platform::class,
39-
MariaDb1060Platform::class => $this->getMySqlPlatformSQLDeclaration($column),
43+
MariaDb1060Platform::class,
44+
MariaDb1010Platform::class => $this->getMySqlPlatformSQLDeclaration($column),
4045
PostgreSQLPlatform::class,
4146
PostgreSQL94Platform::class,
42-
PostgreSQL100Platform::class => $this->getPostgresPlatformSQLDeclaration($column),
47+
PostgreSQL100Platform::class,
48+
PostgreSQL120Platform::class => $this->getPostgresPlatformSQLDeclaration($column),
4349
SQLServerPlatform::class,
4450
SQLServer2012Platform::class => $this->getSqlServerPlatformSQLDeclaration($column),
4551
SqlitePlatform::class => 'DATETIME',

src/Illuminate/Database/Query/Builder.php

+42
Original file line numberDiff line numberDiff line change
@@ -1436,6 +1436,13 @@ public function whereDate($column, $operator, $value = null, $boolean = 'and')
14361436
$value, $operator, func_num_args() === 2
14371437
);
14381438

1439+
// If the given operator is not found in the list of valid operators we will
1440+
// assume that the developer is just short-cutting the '=' operators and
1441+
// we will set the operators to '=' and set the values appropriately.
1442+
if ($this->invalidOperator($operator)) {
1443+
[$value, $operator] = [$operator, '='];
1444+
}
1445+
14391446
$value = $this->flattenValue($value);
14401447

14411448
if ($value instanceof DateTimeInterface) {
@@ -1477,6 +1484,13 @@ public function whereTime($column, $operator, $value = null, $boolean = 'and')
14771484
$value, $operator, func_num_args() === 2
14781485
);
14791486

1487+
// If the given operator is not found in the list of valid operators we will
1488+
// assume that the developer is just short-cutting the '=' operators and
1489+
// we will set the operators to '=' and set the values appropriately.
1490+
if ($this->invalidOperator($operator)) {
1491+
[$value, $operator] = [$operator, '='];
1492+
}
1493+
14801494
$value = $this->flattenValue($value);
14811495

14821496
if ($value instanceof DateTimeInterface) {
@@ -1518,6 +1532,13 @@ public function whereDay($column, $operator, $value = null, $boolean = 'and')
15181532
$value, $operator, func_num_args() === 2
15191533
);
15201534

1535+
// If the given operator is not found in the list of valid operators we will
1536+
// assume that the developer is just short-cutting the '=' operators and
1537+
// we will set the operators to '=' and set the values appropriately.
1538+
if ($this->invalidOperator($operator)) {
1539+
[$value, $operator] = [$operator, '='];
1540+
}
1541+
15211542
$value = $this->flattenValue($value);
15221543

15231544
if ($value instanceof DateTimeInterface) {
@@ -1563,6 +1584,13 @@ public function whereMonth($column, $operator, $value = null, $boolean = 'and')
15631584
$value, $operator, func_num_args() === 2
15641585
);
15651586

1587+
// If the given operator is not found in the list of valid operators we will
1588+
// assume that the developer is just short-cutting the '=' operators and
1589+
// we will set the operators to '=' and set the values appropriately.
1590+
if ($this->invalidOperator($operator)) {
1591+
[$value, $operator] = [$operator, '='];
1592+
}
1593+
15661594
$value = $this->flattenValue($value);
15671595

15681596
if ($value instanceof DateTimeInterface) {
@@ -1608,6 +1636,13 @@ public function whereYear($column, $operator, $value = null, $boolean = 'and')
16081636
$value, $operator, func_num_args() === 2
16091637
);
16101638

1639+
// If the given operator is not found in the list of valid operators we will
1640+
// assume that the developer is just short-cutting the '=' operators and
1641+
// we will set the operators to '=' and set the values appropriately.
1642+
if ($this->invalidOperator($operator)) {
1643+
[$value, $operator] = [$operator, '='];
1644+
}
1645+
16111646
$value = $this->flattenValue($value);
16121647

16131648
if ($value instanceof DateTimeInterface) {
@@ -1974,6 +2009,13 @@ public function whereJsonLength($column, $operator, $value = null, $boolean = 'a
19742009
$value, $operator, func_num_args() === 2
19752010
);
19762011

2012+
// If the given operator is not found in the list of valid operators we will
2013+
// assume that the developer is just short-cutting the '=' operators and
2014+
// we will set the operators to '=' and set the values appropriately.
2015+
if ($this->invalidOperator($operator)) {
2016+
[$value, $operator] = [$operator, '='];
2017+
}
2018+
19772019
$this->wheres[] = compact('type', 'column', 'operator', 'value', 'boolean');
19782020

19792021
if (! $value instanceof ExpressionContract) {

0 commit comments

Comments
 (0)