Skip to content

Commit f812c25

Browse files
committed
Security/EscapeOutput: make basename( __FILE__ ) pattern matching case-insensitive
The sniff has special handling for `_deprecated_file()` calls where the first parameter follows the `basename( __FILE__ )` pattern. The regex pattern was case-sensitive, which meant it would only match lowercase `basename()` and uppercase `__FILE__`. This is incorrect because both function names and magic constants (https://3v4l.org/8nAEV and https://www.php.net/manual/en/language.constants.magic.php) in PHP are case-insensitive. This commit fixes the regex pattern to be case-insensitive.
1 parent adaf62d commit f812c25

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

WordPress/Sniffs/Security/EscapeOutputSniff.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
438438

439439
if ( false !== $file_param ) {
440440
// Check for a particular code pattern which can safely be ignored.
441-
if ( preg_match( '`^[\\\\]?basename\s*\(\s*__FILE__\s*\)$`', $file_param['clean'] ) === 1 ) {
441+
if ( preg_match( '`^[\\\\]?basename\s*\(\s*__FILE__\s*\)$`i', $file_param['clean'] ) === 1 ) {
442442
unset( $params[1], $params['file'] ); // Remove the param, whether passed positionally or named.
443443
}
444444
}

WordPress/Tests/Security/EscapeOutputUnitTest.1.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ $obj = new User_Error( $foo ); // OK.
365365

366366
// Make sure special casing of select functions is handled case-insensitively.
367367
Trigger_ERROR( 'This is fine', $second_param_should_be_ignored ); // OK.
368-
_Deprecated_File( basename( __FILE__ ), '1.3.0' ); // OK.
368+
_Deprecated_File( BASENAME( __file__ ), '1.3.0' ); // OK.
369369
_EX( 'all_params_should_be_ignored_if_function_is_reported_as_unsafe', 'another_param' ); // Bad x 1 for unsafe function.
370370

371371
// Allow for comments in the $file parameter.

0 commit comments

Comments
 (0)