Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix placeholders detection with multiline strings #658

Merged
merged 1 commit into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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']);
}
}
Loading