Merge pull request #19415 from kamil-tekiela/SELECT-with-CASE-crash

Fix crash when SELECT with CASE is executed



Fixes #19328
This commit is contained in:
Maurício Meneghini Fauth 2024-12-04 20:37:25 -03:00 committed by GitHub
commit f28d82fee5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 9 additions and 31 deletions

View File

@ -8337,12 +8337,6 @@ parameters:
count: 1
path: src/Display/Results.php
-
message: '#^Parameter \#5 \$expressions of class PhpMyAdmin\\UniqueCondition constructor expects array\<PhpMyAdmin\\SqlParser\\Components\\Expression\>, array\<PhpMyAdmin\\SqlParser\\Components\\CaseExpression\|PhpMyAdmin\\SqlParser\\Components\\Expression\> given\.$#'
identifier: argument.type
count: 2
path: src/Display/Results.php
-
message: '#^Parameter \#5 \$sortDirection of method PhpMyAdmin\\Display\\Results\:\:getSingleAndMultiSortUrls\(\) expects array\<string\>, array\<mixed\> given\.$#'
identifier: argument.type
@ -8367,12 +8361,6 @@ parameters:
count: 1
path: src/Display/Results.php
-
message: '#^Parameter \$expressions of class PhpMyAdmin\\UniqueCondition constructor expects array\<PhpMyAdmin\\SqlParser\\Components\\Expression\>, array\<PhpMyAdmin\\SqlParser\\Components\\CaseExpression\|PhpMyAdmin\\SqlParser\\Components\\Expression\> given\.$#'
identifier: argument.type
count: 1
path: src/Display/Results.php
-
message: '#^Property PhpMyAdmin\\Display\\Results\:\:\$unlimNumRows \(int\|numeric\-string\|false\) is never assigned false so it can be removed from the property type\.$#'
identifier: property.unusedType
@ -18990,12 +18978,6 @@ parameters:
count: 1
path: src/UniqueCondition.php
-
message: '#^Only booleans are allowed in &&, bool\|string given on the left side\.$#'
identifier: booleanAnd.leftNotBoolean
count: 1
path: src/UniqueCondition.php
-
message: '#^Parameter \#1 \$row of method PhpMyAdmin\\UniqueCondition\:\:getConditionValue\(\) expects float\|int\|string\|null, mixed given\.$#'
identifier: argument.type

View File

@ -4863,9 +4863,6 @@
</file>
<file src="src/Display/Results.php">
<InvalidArgument>
<code><![CDATA[$expressions]]></code>
<code><![CDATA[$expressions]]></code>
<code><![CDATA[$expressions]]></code>
<code><![CDATA[$linkingUrlParams]]></code>
<code><![CDATA[$linkingUrlParams]]></code>
<code><![CDATA[$sortExpressionNoDirection]]></code>
@ -10988,9 +10985,6 @@
<MixedArrayTypeCoercion>
<code><![CDATA[$row[$i]]]></code>
</MixedArrayTypeCoercion>
<RiskyTruthyFalsyComparison>
<code><![CDATA[$restrictToTable]]></code>
</RiskyTruthyFalsyComparison>
</file>
<file src="src/Url.php">
<DeprecatedMethod>

View File

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace PhpMyAdmin;
use PhpMyAdmin\SqlParser\Components\CaseExpression;
use PhpMyAdmin\SqlParser\Components\Expression;
use function bin2hex;
@ -23,18 +24,18 @@ class UniqueCondition
/**
* Function to generate unique condition for specified row.
*
* @param FieldMetadata[] $fieldsMeta meta information about fields
* @param array $row current row
* @param bool $forceUnique generate condition only on pk or unique
* @param string|bool $restrictToTable restrict the unique condition to this table or false if none
* @param Expression[] $expressions An array of Expression instances.
* @param FieldMetadata[] $fieldsMeta meta information about fields
* @param array $row current row
* @param bool $forceUnique generate condition only on pk or unique
* @param string $restrictToTable restrict the unique condition to this table
* @param (Expression|CaseExpression)[] $expressions An array of Expression instances.
* @psalm-param array<int, mixed> $row
*/
public function __construct(
array $fieldsMeta,
array $row,
bool $forceUnique = false,
string|bool $restrictToTable = false,
string $restrictToTable = '',
array $expressions = [],
) {
$fieldsCount = count($fieldsMeta);
@ -54,6 +55,7 @@ class UniqueCondition
foreach ($expressions as $expression) {
if (
$expression->alias === null || $expression->alias === ''
|| $expression instanceof CaseExpression
|| $expression->column === null || $expression->column === ''
) {
continue;
@ -84,7 +86,7 @@ class UniqueCondition
// If this field is not from the table which the unique clause needs
// to be restricted to.
if ($restrictToTable && $restrictToTable != $meta->table) {
if ($restrictToTable !== '' && $restrictToTable != $meta->table) {
continue;
}