Skip to content

Commit

Permalink
Fix placeholders detection with multiline strings (#658)
Browse files Browse the repository at this point in the history
  • Loading branch information
b-viguier committed Jun 4, 2024
1 parent 33e9f47 commit 9b3f8f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/QueryReflection/QueryReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ final class QueryReflection
// see https://github.com/php/php-src/blob/01b3fc03c30c6cb85038250bb5640be3a09c6a32/ext/pdo/pdo_sql_parser.re#L48
private const NAMED_PATTERN = ':[a-zA-Z0-9_]+';

private const REGEX_UNNAMED_PLACEHOLDER = '{(["\'])((?:(?!\1).)*\1)|(' . self::UNNAMED_PATTERN . ')}';
private const REGEX_UNNAMED_PLACEHOLDER = '{(["\'])((?:(?!\1)(?s:.))*\1)|(' . self::UNNAMED_PATTERN . ')}';

private const REGEX_NAMED_PLACEHOLDER = '{(["\'])((?:(?!\1).)*\1)|(' . self::NAMED_PATTERN . ')}';
private const REGEX_NAMED_PLACEHOLDER = '{(["\'])((?:(?!\1)(?s:.))*\1)|(' . self::NAMED_PATTERN . ')}';

/**
* @var QueryReflector|null
Expand Down
10 changes: 10 additions & 0 deletions tests/rules/data/pdo-stmt-execute-error.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,14 @@ public function supportNestedQuotes(PDO $pdo)
);
$stmt->execute(['value' => 'bar']);
}

public function bug657MultilineString(PDO $pdo)
{
$stmt = $pdo->prepare(<<<SQL
UPDATE `ada` SET email = "multi
line" WHERE `email`= ? AND `email` = "value";
SQL
);
$stmt->execute(['value']);
}
}

0 comments on commit 9b3f8f2

Please sign in to comment.