Skip to content

Commit 0d6763d

Browse files
committed
Security/EscapeOutput: add edge case tests for basename(__FILE__) pattern
Add tests to ensure the basename(__FILE__) pattern recognition in `_deprecated_file()` only applies to global `basename()` function calls, not to other constructs that might look similar.
1 parent 27701fd commit 0d6763d

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

WordPress/Tests/Security/EscapeOutputUnitTest.1.inc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,3 +752,17 @@ namespace\Sub\user_error( $message ); // Ok.
752752
namespace\_deprecated_file( basename( __FILE__ ), '1.3.0' ); // Ok.
753753
namespace\_DEPRECATED_FILE( $file, '1.3.0' ); // Ok. The sniff should start flagging this once it can resolve relative namespaces.
754754
namespace\Sub\_deprecated_file( $file, '1.3.0' ); // Ok.
755+
756+
/*
757+
* Safeguard that the basename( __FILE__ ) pattern recognition in _deprecated_file() only applies to
758+
* the global basename() function and not to other constructs.
759+
*/
760+
_deprecated_file( $obj->basename( __FILE__ ), '1.3.0' ); // Bad.
761+
_deprecated_file( $obj?->basename( __FILE__ ), '1.3.0' ); // Bad.
762+
_deprecated_file( MyClass::basename( __FILE__ ), '1.3.0' ); // Bad.
763+
_deprecated_file( BASENAME, __FILE__ ); // Bad.
764+
_deprecated_file( MyNamespace\basename( __FILE__ ), '1.3.0' ); // Bad.
765+
_deprecated_file( \MyNamespace\basename( __FILE__ ), '1.3.0' ); // Bad.
766+
_deprecated_file( namespace\basename( __FILE__ ), '1.3.0' ); // Bad. We might want to update the regex so that the sniff stop flagging this once it can resolve relative namespaces.
767+
_deprecated_file( namespace\Sub\basename( __FILE__ ), '1.3.0' ); // Bad.
768+
_deprecated_file( basename(...), '1.3.0' ); // Bad.

WordPress/Tests/Security/EscapeOutputUnitTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,15 @@ public function getErrorList( $testFile = '' ) {
191191
741 => 1,
192192
747 => 1,
193193
751 => 1,
194+
760 => 1,
195+
761 => 1,
196+
762 => 1,
197+
763 => 1,
198+
764 => 1,
199+
765 => 1,
200+
766 => 1,
201+
767 => 1,
202+
768 => 1,
194203
);
195204

196205
case 'EscapeOutputUnitTest.6.inc':

0 commit comments

Comments
 (0)