Skip to content

Commit

Permalink
Sniff update WIP
Browse files Browse the repository at this point in the history
Need to write a recursive method that will check the fully qualified class names and if they have a static method call in them. We should also be careful not to catch the throw Exception cases, as for those we do want to check the parameters of the static method if they are escaped or not.
  • Loading branch information
dingo-d committed Aug 30, 2023
1 parent d02caaf commit ef75f3f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions WordPress/Sniffs/Security/EscapeOutputSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -738,13 +738,25 @@ protected function check_code_is_escaped( $start, $end ) {
$content = $functionName;

// Check if it's static method call.
$double_colon = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), $end, true );
if ( false !== $double_colon
$next_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, ( $i + 1 ), $end, true );
if ( false !== $next_non_empty
&& \T_DOUBLE_COLON === $this->tokens[ $double_colon ]['code']

Check failure on line 743 in WordPress/Sniffs/Security/EscapeOutputSniff.php

View workflow job for this annotation

GitHub Actions / PHPStan

Variable $double_colon might not be defined.

Check failure on line 743 in WordPress/Sniffs/Security/EscapeOutputSniff.php

View workflow job for this annotation

GitHub Actions / PHPStan

Variable $double_colon might not be defined.
) {
// Set the pointer to the end of the method.
$i = $this->phpcsFile->findNext( \T_CLOSE_PARENTHESIS, $i, $end );
}

// Check if the class is fully qualified (namespaced), then check for the double colon (static method).
if ( false !== $next_non_empty

Check failure on line 750 in WordPress/Sniffs/Security/EscapeOutputSniff.php

View workflow job for this annotation

GitHub Actions / Run code sniffs

Empty IF statement detected

Check failure on line 750 in WordPress/Sniffs/Security/EscapeOutputSniff.php

View workflow job for this annotation

GitHub Actions / Run code sniffs

Empty IF statement detected
&& \T_NS_SEPARATOR === $this->tokens[ $double_colon ]['code']

Check failure on line 751 in WordPress/Sniffs/Security/EscapeOutputSniff.php

View workflow job for this annotation

GitHub Actions / PHPStan

Variable $double_colon might not be defined.

Check failure on line 751 in WordPress/Sniffs/Security/EscapeOutputSniff.php

View workflow job for this annotation

GitHub Actions / PHPStan

Variable $double_colon might not be defined.
) {

}

// Checking for fully qualified name - go and find all the T_STRING and T_NS_SEPARATOR until the T_DOUBLE_COLON token.

Check failure on line 757 in WordPress/Sniffs/Security/EscapeOutputSniff.php

View workflow job for this annotation

GitHub Actions / Run code sniffs

Functions must not contain multiple empty lines in a row; found 3 empty lines

Check failure on line 757 in WordPress/Sniffs/Security/EscapeOutputSniff.php

View workflow job for this annotation

GitHub Actions / Run code sniffs

Functions must not contain multiple empty lines in a row; found 3 empty lines


} else {
$content = $this->tokens[ $i ]['content'];
$ptr = $i;
Expand Down

0 comments on commit ef75f3f

Please sign in to comment.