Skip to content

Commit dafc562

Browse files
committed
Security/PHPFilterFunctions: remove redundant strtoupper() calls
The `isset( $this->restricted_filters[ $parameters[3]['raw'] ] )` check on the array is case-sensitive, so if the filter constant name was not in upper case already, it wouldn't be matched anyhow. Also note: the case-sensitivity is correct as constants in PHP are case-sensitive (unless explicitly declared as case-insensitive, which these aren't: https://3v4l.org/vq53U#veol). Includes updating one of the pre-existing tests to document this.
1 parent 8581c40 commit dafc562

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

WordPressVIPMinimum/Sniffs/Security/PHPFilterFunctionsSniff.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
6969

7070
if ( isset( $parameters[3], $this->restricted_filters[ $parameters[3]['raw'] ] ) ) {
7171
$message = 'Please use an appropriate filter to sanitize, as "%s" does no filtering, see: http://php.net/manual/en/filter.filters.sanitize.php.';
72-
$data = [ strtoupper( $parameters[3]['raw'] ) ];
72+
$data = [ $parameters[3]['raw'] ];
7373
$this->phpcsFile->addWarning( $message, $stackPtr, 'RestrictedFilter', $data );
7474
}
7575
} else {
@@ -81,7 +81,7 @@ public function process_parameters( $stackPtr, $group_name, $matched_content, $p
8181

8282
if ( isset( $parameters[2], $this->restricted_filters[ $parameters[2]['raw'] ] ) ) {
8383
$message = 'Please use an appropriate filter to sanitize, as "%s" does no filtering, see http://php.net/manual/en/filter.filters.sanitize.php.';
84-
$data = [ strtoupper( $parameters[2]['raw'] ) ];
84+
$data = [ $parameters[2]['raw'] ];
8585
$this->phpcsFile->addWarning( $message, $stackPtr, 'RestrictedFilter', $data );
8686
}
8787
}

WordPressVIPMinimum/Tests/Security/PHPFilterFunctionsUnitTest.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ filter_var( $url, FILTER_SANITIZE_URL );
2828
\filter_var( 'test', FILTER_SANITIZE_STRING );
2929
FILTER_INPUT( INPUT_GET, 'foo', FILTER_SANITIZE_STRING, );
3030
filter_input( INPUT_GET, "foo" , FILTER_SANITIZE_STRING );
31-
filter_input_array( $array, FILTER_SANITIZE_STRING );
31+
filter_input_array( $array, filter_default ); // Constants are case-sensitive, so this is not the FILTER_DEFAULT constant.
3232

3333
// Ignore as undetermined.
3434
filter_var( "test", get_filter() );

0 commit comments

Comments
 (0)