diff --git a/WordPress/Sniff.php b/WordPress/Sniff.php index e688876d45..b0ba2031e6 100644 --- a/WordPress/Sniff.php +++ b/WordPress/Sniff.php @@ -1505,7 +1505,8 @@ protected function is_in_isset_or_empty( $stackPtr ) { end( $nested_parenthesis ); $open_parenthesis = key( $nested_parenthesis ); - return \in_array( $this->tokens[ ( $open_parenthesis - 1 ) ]['code'], array( \T_ISSET, \T_EMPTY ), true ); + $previous_non_empty = $this->phpcsFile->findPrevious( Tokens::$emptyTokens, ( $open_parenthesis - 1 ), null, true, null, true); + return in_array( $this->tokens[ $previous_non_empty ]['code'], array( \T_ISSET, \T_EMPTY ), true ); } /** diff --git a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc index 376e05db4f..46d5498248 100644 --- a/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc +++ b/WordPress/Tests/Security/ValidatedSanitizedInputUnitTest.inc @@ -163,3 +163,18 @@ EOD if ( ( $_POST['foo'] ?? 'post' ) === 'post' ) {} // OK. if ( ( $_POST['foo'] <=> 'post' ) === 0 ) {} // OK. + +// Test whitespace independent isset/empty detection. +function foobar() { + if ( ! isset ($_GET['test']) ) { + return ; + } + echo sanitize_text_field( wp_unslash( $_GET['test'] ) ); // OK. +} + +function barfoo() { + if ( empty ($_GET['test']) ) { + return ; + } + echo sanitize_text_field( wp_unslash( $_GET['test'] ) ); // OK. +}