Skip to content

Commit f69e595

Browse files
committed
Security/ValidatedSanitizedInput: make MissingUnslash message more informative
Previously, the error would read `$_POST data not unslashed...`. Now, the error message will show the exact variable with keys we're talking about like `$_POST['key'] not unslashed...`.
1 parent be30b5e commit f69e595

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

WordPress/Sniffs/Security/ValidatedSanitizedInputSniff.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,15 @@ public function add_unslash_error( File $phpcsFile, $stackPtr ) {
230230
return;
231231
}
232232

233+
// We know there will be array keys as that's checked in the process_token() method.
234+
$array_keys = VariableHelper::get_array_access_keys( $phpcsFile, $stackPtr );
235+
$error_data = array( $var_name . '[' . implode( '][', $array_keys ) . ']' );
236+
233237
$phpcsFile->addError(
234-
'%s data not unslashed before sanitization. Use wp_unslash() or similar',
238+
'%s not unslashed before sanitization. Use wp_unslash() or similar',
235239
$stackPtr,
236240
'MissingUnslash',
237-
array( $var_name )
241+
$error_data
238242
);
239243
}
240244
}

0 commit comments

Comments
 (0)