Skip to content

Commit

Permalink
Fix false-positive parameter validation error when query string is no…
Browse files Browse the repository at this point in the history
…t resolvable (#630)
  • Loading branch information
staabm committed Sep 29, 2023
1 parent 4154548 commit ccabc0c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/QueryReflection/PlaceholderValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public function checkQuery(Expr $queryExpr, Scope $scope, array $parameters): it
}
}

if ($queryStrings === []) {
return;
}

if ($namedPlaceholders) {
yield from $this->validateNamedPlaceholders($queryStrings, $parameters);

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

$minPlaceholderCount = PHP_INT_MAX;
$maxPlaceholderCount = 0;
foreach ($queryStrings as $queryString) {
$placeholderCount = $queryReflection->countPlaceholders($queryString);
foreach ($queryStrings as $unnamedQueryString) {
$placeholderCount = $queryReflection->countPlaceholders($unnamedQueryString);
if ($placeholderCount < $minPlaceholderCount) {
$minPlaceholderCount = $placeholderCount;
}
Expand Down
8 changes: 8 additions & 0 deletions tests/rules/data/placeholder-bug.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,12 @@ public function wrongMinBound(PDO $pdo)
$stmt = $pdo->prepare('SELECT email, adaid FROM ada WHERE adaid = ? OR adaid = ? ');
$stmt->execute([]);
}

public function notResolvableQuery(PDO $pdo, $params)
{
$query ='SELECT email, adaid FROM ada WHERE email = ? '.$params;

$stmt = $pdo->prepare($query);
$stmt->execute(['hello world']);
}
}

0 comments on commit ccabc0c

Please sign in to comment.