@@ -263,7 +263,7 @@ public function process_token( $stackPtr ) {
263
263
264
264
// Examine each parameter individually.
265
265
foreach ( $ params as $ param ) {
266
- $ this ->check_code_is_escaped ( $ param ['start ' ], ( $ param ['end ' ] + 1 ) );
266
+ $ this ->check_code_is_escaped ( $ param ['start ' ], ( $ param ['end ' ] + 1 ), ' ExceptionNotEscaped ' );
267
267
}
268
268
269
269
return $ end ;
@@ -446,12 +446,13 @@ public function process_matched_token( $stackPtr, $group_name, $matched_content
446
446
*
447
447
* @since 3.0.0 Split off from the process_token() method.
448
448
*
449
- * @param int $start The position to start checking from.
450
- * @param int $end The position to stop the check at.
449
+ * @param int $start The position to start checking from.
450
+ * @param int $end The position to stop the check at.
451
+ * @param string $code Code to use for the PHPCS error.
451
452
*
452
453
* @return int Integer stack pointer to skip forward.
453
454
*/
454
- protected function check_code_is_escaped ( $ start , $ end ) {
455
+ protected function check_code_is_escaped ( $ start , $ end, $ code = ' OutputNotEscaped ' ) {
455
456
/*
456
457
* Check for a ternary operator.
457
458
* We only need to do this here if this statement is lacking parenthesis.
@@ -532,7 +533,7 @@ protected function check_code_is_escaped( $start, $end ) {
532
533
533
534
// Handle PHP 8.0+ match expressions.
534
535
if ( \T_MATCH === $ this ->tokens [ $ i ]['code ' ] ) {
535
- $ match_valid = $ this ->walk_match_expression ( $ i );
536
+ $ match_valid = $ this ->walk_match_expression ( $ i, $ code );
536
537
if ( false === $ match_valid ) {
537
538
// Live coding or parse error. Shouldn't be possible as PHP[CS] will tokenize the keyword as `T_STRING` in that case.
538
539
break ; // @codeCoverageIgnore
@@ -553,7 +554,7 @@ protected function check_code_is_escaped( $start, $end ) {
553
554
$ array_items = PassedParameters::getParameters ( $ this ->phpcsFile , $ i , 0 , true );
554
555
if ( ! empty ( $ array_items ) ) {
555
556
foreach ( $ array_items as $ array_item ) {
556
- $ this ->check_code_is_escaped ( $ array_item ['start ' ], ( $ array_item ['end ' ] + 1 ) );
557
+ $ this ->check_code_is_escaped ( $ array_item ['start ' ], ( $ array_item ['end ' ] + 1 ), $ code );
557
558
}
558
559
}
559
560
@@ -699,7 +700,7 @@ protected function check_code_is_escaped( $start, $end ) {
699
700
$ formatting_params = PassedParameters::getParameters ( $ this ->phpcsFile , $ i );
700
701
if ( ! empty ( $ formatting_params ) ) {
701
702
foreach ( $ formatting_params as $ format_param ) {
702
- $ this ->check_code_is_escaped ( $ format_param ['start ' ], ( $ format_param ['end ' ] + 1 ) );
703
+ $ this ->check_code_is_escaped ( $ format_param ['start ' ], ( $ format_param ['end ' ] + 1 ), $ code );
703
704
}
704
705
}
705
706
@@ -754,7 +755,7 @@ protected function check_code_is_escaped( $start, $end ) {
754
755
$ this ->phpcsFile ->addError (
755
756
"All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found '%s'. " ,
756
757
$ ptr ,
757
- ' OutputNotEscaped ' ,
758
+ $ code ,
758
759
array ( $ content )
759
760
);
760
761
}
@@ -825,11 +826,12 @@ private function find_long_ternary( $start, $end ) {
825
826
*
826
827
* @since 3.0.0
827
828
*
828
- * @param int $stackPtr Pointer to a T_MATCH token.
829
+ * @param int $stackPtr Pointer to a T_MATCH token.
830
+ * @param string $code Code to use for the PHPCS error.
829
831
*
830
832
* @return int|false Stack pointer to skip to or FALSE if the match expression contained a parse error.
831
833
*/
832
- private function walk_match_expression ( $ stackPtr ) {
834
+ private function walk_match_expression ( $ stackPtr, $ code ) {
833
835
if ( ! isset ( $ this ->tokens [ $ stackPtr ]['scope_opener ' ], $ this ->tokens [ $ stackPtr ]['scope_closer ' ] ) ) {
834
836
// Parse error/live coding. Shouldn't be possible as PHP[CS] will tokenize the keyword as `T_STRING` in that case.
835
837
return false ; // @codeCoverageIgnore
@@ -889,7 +891,7 @@ private function walk_match_expression( $stackPtr ) {
889
891
}
890
892
891
893
// Now check that the value returned by this match "leaf" is correctly escaped.
892
- $ this ->check_code_is_escaped ( $ item_start , $ item_end );
894
+ $ this ->check_code_is_escaped ( $ item_start , $ item_end, $ code );
893
895
894
896
// Independently of whether or not the check was succesfull or ran into (parse error) problems,
895
897
// always skip to the identified end of the item.
0 commit comments