Skip to content

Commit f2fbb58

Browse files
committed
DB/PreparedSQLPlaceholders: fix false negative when checking quotes in dynamic generated placeholders
The sniff was not accounting for fully qualified calls to `implode()` in the code that checks for quotes in dynamically generated placeholders.
1 parent afcb17e commit f2fbb58

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

WordPress/Sniffs/DB/PreparedSQLPlaceholdersSniff.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,8 +266,13 @@ public function process_token( $stackPtr ) {
266266
unset( $sprintf_parameters, $valid_sprintf, $last_param );
267267

268268
} elseif ( 'implode' === strtolower( $this->tokens[ $i ]['content'] ) ) {
269+
$ignore_tokens = Tokens::$emptyTokens + array(
270+
\T_STRING_CONCAT => \T_STRING_CONCAT,
271+
\T_NS_SEPARATOR => \T_NS_SEPARATOR,
272+
);
273+
269274
$prev = $this->phpcsFile->findPrevious(
270-
Tokens::$emptyTokens + array( \T_STRING_CONCAT => \T_STRING_CONCAT ),
275+
$ignore_tokens,
271276
( $i - 1 ),
272277
$query['start'],
273278
true

WordPress/Tests/DB/PreparedSQLPlaceholdersUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ $where = $wpdb->prepare(
148148
"{$wpdb->posts}.post_type IN (\""
149149
. implode( ',', array_fill( 0, count($post_types), '%s' ) )
150150
. "\") AND {$wpdb->posts}.post_status IN ('"
151-
. implode( ',', array_fill( 0, count($post_statusses), '%s' ) )
151+
. \implode( ',', array_fill( 0, count($post_statusses), '%s' ) )
152152
. '\')',
153153
array_merge( $post_types, $post_statusses )
154154
); // Bad x 2 - quotes between the () for the IN.

0 commit comments

Comments
 (0)