WordPress-Coding-Standards icon indicating copy to clipboard operation
WordPress-Coding-Standards copied to clipboard

EscapeOutput: False positive for _doing_it_wrong with constant

Open mundschenk-at opened this issue 3 years ago • 1 comments

Bug Description

When I replace

_doing_it_wrong( __FUNCTION__, 'My message', '1.0.0' );

with

const MY_MESSAGE = 'My message';
_doing_it_wrong( __FUNCTION__, MY_MESSAGE, '1.0.0' );

I get a WordPress.Security.EscapeOutput.OutputNotEscaped error. I assume this is a false positive. If the message really should be escaped, the plain string version should result in the same the error.

Error Code

WordPress.Security.EscapeOutput.OutputNotEscaped

Environment

  • PHP: 7.4.21
  • PHPCS: 3.6.0
  • WPCS: 2.3.0

Tested Against develop branch?

  • [x] I have verified the issue still exists in the develop branch of WPCS.

mundschenk-at avatar Jul 17 '21 14:07 mundschenk-at

@mundschenk-at This is not a false positive. As constants can be declared anywhere in the code base and even outside it - like in a dependency - WPCS does not have access to the value of the constant and can't evaluate whether it is safe.

The constant could be a constant declared in a config file by an admin user, or when declared using define() could contain the result of user input like $_GET.

The plain text string used in the first example however is not susceptible to any form of code injection and is therefore not flagged.

jrfnl avatar Jul 29 '21 11:07 jrfnl

Closing as invalid, no action planned.

jrfnl avatar Sep 23 '22 16:09 jrfnl