From 9b3f8f25efa262f5b5da9b86e20b74002019f5bc Mon Sep 17 00:00:00 2001 From: Benoit Date: Tue, 4 Jun 2024 13:11:49 +0100 Subject: [PATCH] Fix placeholders detection with multiline strings (#658) --- src/QueryReflection/QueryReflection.php | 4 ++-- tests/rules/data/pdo-stmt-execute-error.php | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/QueryReflection/QueryReflection.php b/src/QueryReflection/QueryReflection.php index 5fa6caad0..f09baa9ac 100644 --- a/src/QueryReflection/QueryReflection.php +++ b/src/QueryReflection/QueryReflection.php @@ -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 diff --git a/tests/rules/data/pdo-stmt-execute-error.php b/tests/rules/data/pdo-stmt-execute-error.php index 40d08b92b..ec54910c5 100644 --- a/tests/rules/data/pdo-stmt-execute-error.php +++ b/tests/rules/data/pdo-stmt-execute-error.php @@ -136,4 +136,14 @@ public function supportNestedQuotes(PDO $pdo) ); $stmt->execute(['value' => 'bar']); } + + public function bug657MultilineString(PDO $pdo) + { + $stmt = $pdo->prepare(<<execute(['value']); + } }