Skip to content

Commit 7079671

Browse files
authored
Support nested quotes (#651)
1 parent d20f0bc commit 7079671

8 files changed

+6021
-7373
lines changed

.phpstan-dba-mysqli.cache

Lines changed: 693 additions & 204 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.phpstan-dba-pdo-mysql.cache

Lines changed: 617 additions & 389 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/QueryReflection/QueryReflection.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,9 @@ final class QueryReflection
4242
// see https://github.com/php/php-src/blob/01b3fc03c30c6cb85038250bb5640be3a09c6a32/ext/pdo/pdo_sql_parser.re#L48
4343
private const NAMED_PATTERN = ':[a-zA-Z0-9_]+';
4444

45-
private const REGEX_UNNAMED_PLACEHOLDER = '{(["\'])([^"\']*\1)|(' . self::UNNAMED_PATTERN . ')}';
45+
private const REGEX_UNNAMED_PLACEHOLDER = '{(["\'])((?:(?!\1).)*\1)|(' . self::UNNAMED_PATTERN . ')}';
4646

47-
private const REGEX_NAMED_PLACEHOLDER = '{(["\'])([^"\']*\1)|(' . self::NAMED_PATTERN . ')}';
47+
private const REGEX_NAMED_PLACEHOLDER = '{(["\'])((?:(?!\1).)*\1)|(' . self::NAMED_PATTERN . ')}';
4848

4949
/**
5050
* @var QueryReflector|null

tests/rules/SyntaxErrorInQueryFunctionRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ public function testMysqliExecuteQuery(): void
115115
self::markTestSkipped('Test requires PHP 8.2.');
116116
}
117117

118+
if (MysqliQueryReflector::NAME !== getenv('DBA_REFLECTOR')) {
119+
self::markTestSkipped('mysqli test only.');
120+
}
121+
118122
$this->analyse([__DIR__ . '/data/mysqli_execute_query.php'], [
119123
[
120124
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",

tests/rules/SyntaxErrorInQueryMethodRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ public function testMysqliExecuteQuery(): void
292292
self::markTestSkipped('Test requires PHP 8.2.');
293293
}
294294

295+
if (MysqliQueryReflector::NAME !== getenv('DBA_REFLECTOR')) {
296+
self::markTestSkipped('mysqli test only.');
297+
}
298+
295299
$this->analyse([__DIR__ . '/data/mysqli_execute_query.php'], [
296300
[
297301
"Query error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL/MariaDB server version for the right syntax to use near 'freigabe1u1 FROM ada LIMIT 0' at line 1 (1064).",

tests/rules/config/.phpunit-phpstan-dba-mysqli.cache

Lines changed: 2346 additions & 3397 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/rules/config/.phpunit-phpstan-dba-pdo-mysql.cache

Lines changed: 2346 additions & 3381 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/rules/data/pdo-stmt-execute-error.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,13 @@ public function bug422UnnamedPlaceholdersInCommentInsideOfQuery(PDO $pdo)
127127
$stmt = $pdo->prepare('SELECT email, adaid /* why? ? */ FROM ada /* just ?? :because ?*/ WHERE email = :email -- ?');
128128
$stmt->execute(['email' => 'a']);
129129
}
130+
131+
public function supportNestedQuotes(PDO $pdo)
132+
{
133+
$stmt = $pdo->prepare(<<<SQL
134+
SELECT payload ->> '$."dash-separated"' = :value FROM ada WHERE 'foo'
135+
SQL
136+
);
137+
$stmt->execute(['value' => 'bar']);
138+
}
130139
}

0 commit comments

Comments
 (0)