Skip to content
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
7 changes: 6 additions & 1 deletion WordPress/Sniffs/Security/EscapeOutputSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,13 @@ protected function check_code_is_escaped( $start, $end, $code = 'OutputNotEscape
if ( \T_STRING === $this->tokens[ $i ]['code']
|| \T_VARIABLE === $this->tokens[ $i ]['code']
|| isset( Collections::ooHierarchyKeywords()[ $this->tokens[ $i ]['code'] ] )
|| \T_NAMESPACE === $this->tokens[ $i ]['code']
) {
$double_colon = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), $end, true );
$skip_tokens = Tokens::$emptyTokens;
$skip_tokens[ \T_STRING ] = \T_STRING;
$skip_tokens[ \T_NS_SEPARATOR ] = \T_NS_SEPARATOR;
Comment on lines +621 to +622
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record: these extra tokens are only relevant when the $i token is T_STRING or T_NAMESPACE.
I can't think of a valid code sample with T_VARIABLE or the hierarchy tokens where it would be problematic though, but give PHP a few years and no doubt it will be ;-)
(but no need to change it until PHP changes)


$double_colon = $this->phpcsFile->findNext( $skip_tokens, ( $i + 1 ), $end, true );
if ( false !== $double_colon
&& \T_DOUBLE_COLON === $this->tokens[ $double_colon ]['code']
) {
Expand Down
13 changes: 12 additions & 1 deletion WordPress/Tests/Security/EscapeOutputUnitTest.1.inc
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ _deprecated_function( __METHOD__, 'x.x.x', ClassName::class ); // OK.
die( self::CLASS . ' has been abandoned' ); // OK.
_deprecated_function( __METHOD__, 'x.x.x', parent::Class ); // OK.
_deprecated_function( __METHOD__, 'x.x.x', static::class ); // OK.
echo 'Do not use ' . $object::class ); // OK.
echo 'Do not use ' . $object::class; // OK.

/*
* Examine the parameters passed for exception creation via throw.
Expand Down Expand Up @@ -676,3 +676,14 @@ throw new
/* some comment */
#[Attribute2('text', 10)]
readonly class( $unescaped ) {}; // Bad.

/*
* Safeguard correct handling of all types of namespaced function calls when *::class is used.
*
* Note: using ::class on fully qualified or namespace relative class names doesn't provide
* any real value in practice.
*/
_deprecated_function( __METHOD__, 'x.x.x', \ClassName::class ); // OK.
die( \MyNamespace\ClassName::class . ' has been abandoned' ); // OK.
echo 'Do not use ' . MyNamespace\ClassName::class; // OK.
_deprecated_function( __METHOD__, 'x.x.x', namespace\ClassName::class ); // OK.
Loading