Skip to content

Commit c65e55c

Browse files
committed
Security/PHPFilterFunctions: report restricted filter on the correct token
Throw the warning about the use of a restricted filter on the actual filter constant, not on the function call token. This will more clearly indicate the issue when people use the PHPCS `code` view.
1 parent e10dd27 commit c65e55c

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

WordPressVIPMinimum/Sniffs/Security/PHPFilterFunctionsSniff.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace WordPressVIPMinimum\Sniffs\Security;
1111

12+
use PHP_CodeSniffer\Util\Tokens;
1213
use PHPCSUtils\Utils\PassedParameters;
1314
use WordPressCS\WordPress\AbstractFunctionParameterSniff;
1415

@@ -92,9 +93,11 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
9293
}
9394

9495
if ( isset( $this->restricted_filters[ $target_param['clean'] ] ) ) {
96+
$first_non_empty = $this->phpcsFile->findNext( Tokens::$emptyTokens, $target_param['start'], ( $target_param['end'] + 1 ), true );
97+
9598
$message = 'Please use an appropriate filter to sanitize, as "%s" does no filtering, see: http://php.net/manual/en/filter.filters.sanitize.php.';
9699
$data = [ $target_param['clean'] ];
97-
$this->phpcsFile->addWarning( $message, $stackPtr, 'RestrictedFilter', $data );
100+
$this->phpcsFile->addWarning( $message, $first_non_empty, 'RestrictedFilter', $data );
98101
}
99102
}
100103
}

WordPressVIPMinimum/Tests/Security/PHPFilterFunctionsUnitTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function getWarningList() {
4444
56 => 1,
4545
57 => 1,
4646
58 => 1,
47-
63 => 1,
47+
65 => 1,
4848
70 => 1,
4949
71 => 1,
5050
73 => 1,

0 commit comments

Comments
 (0)