Skip to content

Commit ccabc0c

Browse files
authored
Fix false-positive parameter validation error when query string is not resolvable (#630)
1 parent 4154548 commit ccabc0c

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/QueryReflection/PlaceholderValidation.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ public function checkQuery(Expr $queryExpr, Scope $scope, array $parameters): it
2828
}
2929
}
3030

31+
if ($queryStrings === []) {
32+
return;
33+
}
34+
3135
if ($namedPlaceholders) {
3236
yield from $this->validateNamedPlaceholders($queryStrings, $parameters);
3337

@@ -36,8 +40,8 @@ public function checkQuery(Expr $queryExpr, Scope $scope, array $parameters): it
3640

3741
$minPlaceholderCount = PHP_INT_MAX;
3842
$maxPlaceholderCount = 0;
39-
foreach ($queryStrings as $queryString) {
40-
$placeholderCount = $queryReflection->countPlaceholders($queryString);
43+
foreach ($queryStrings as $unnamedQueryString) {
44+
$placeholderCount = $queryReflection->countPlaceholders($unnamedQueryString);
4145
if ($placeholderCount < $minPlaceholderCount) {
4246
$minPlaceholderCount = $placeholderCount;
4347
}

tests/rules/data/placeholder-bug.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,12 @@ public function wrongMinBound(PDO $pdo)
4747
$stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? ');
4848
$stmt->execute([]);
4949
}
50+
51+
public function notResolvableQuery(PDO $pdo, $params)
52+
{
53+
$query ='SELECT email, adaid FROM ada WHERE email = ? '.$params;
54+
55+
$stmt = $pdo->prepare($query);
56+
$stmt->execute(['hello world']);
57+
}
5058
}

0 commit comments

Comments
 (0)