-
-
Notifications
You must be signed in to change notification settings - Fork 523
Closed
Description
Bug Description
The sniff incorrectly handles namespaced function calls by checking each token individually. This causes a few problems:
- When the namespace prefix doesn't match a known function, only the prefix is flagged in the error message instead of the full namespaced function name.
- The array walking function logic is incorrectly applied to namespaced functions that happen to share the same name as a valid global array walking function.
- When the namespace prefix matches an allowed function name, the sniff treats it as an allowed function.
The sniff should treat namespaced function calls as a single unit:
- Flag the full namespaced name in error messages.
- Do not apply special logic to namespaced functions that merely share the same name as global functions.
- Recognize that
MyNamespace\function_name()is not the globalfunction_name().
Minimal Code Snippet
The issue happens when running this command:
phpcs --standard=WordPress --sniffs=WordPress.Security.EscapeOutput test.php... over a file containing this code:
// Incorrect error message (should flag 'MyNamespace\esc_html')
echo MyNamespace\esc_html( $foo );
// Current: found 'MyNamespace'
// Expected: found 'MyNamespace\esc_html'
// Inconsistent handling - 2 errors for MyNamespace\array_map() and 1 error for MyNamespace\map_deep()
echo implode( '<br>', MyNamespace\array_map( 'esc_html', $items ) );
echo implode( '<br>', MyNamespace\map_deep( $items, 'esc_html' ) ); // Bad.
// Completely missed - no error (should flag 'esc_html\esc_html')
echo esc_html\esc_html( $foo );Error Code
WordPress.Security.EscapeOutput.OutputNotEscaped
Environment
| Question | Answer |
|---|---|
| PHP version | 8.4 |
| PHP_CodeSniffer version | 3.13.5 |
| WordPressCS version | develop |
| PHPCSUtils version | 1.2.1 |
| PHPCSExtra version | 1.5.0 |
| WordPressCS install type | git clone |
| IDE (if relevant) | N/A |
Additional Context (optional)
It needs to be checked, but those issues probably don't happen when running WPCS with PHPCS 4.0. If that is the case, I would suggest waiting for PHPCS 3.x support to be dropped to close this issue instead of working on a fix, as this is probably low priority.
Tested Against develop Branch?
- I have verified the issue still exists in the
developbranch of WordPressCS.