@@ -361,6 +361,25 @@ abstract class Sniff implements PHPCS_Sniff {
361361 \T_BOOL_CAST => true ,
362362 );
363363
364+ /**
365+ * List of array functions which apply a callback to the array.
366+ *
367+ * These are often used for sanitization/escaping an array variable.
368+ *
369+ * Note: functions which alter the array by reference are not listed here on purpose.
370+ * These cannot easily be used for sanitization as they can't be combined with unslashing.
371+ * Similarly, they cannot be used for late escaping as the return value is a boolean, not
372+ * the altered array.
373+ *
374+ * @since 2.1.0
375+ *
376+ * @var array <string function name> => <int parameter position of the callback parameter>
377+ */
378+ protected $ arrayWalkingFunctions = array (
379+ 'array_map ' => 1 ,
380+ 'map_deep ' => 2 ,
381+ );
382+
364383 /**
365384 * Functions that format strings.
366385 *
@@ -1789,8 +1808,8 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) {
17891808
17901809 $ valid_functions = $ this ->sanitizingFunctions ;
17911810 $ valid_functions += $ this ->unslashingSanitizingFunctions ;
1811+ $ valid_functions += $ this ->arrayWalkingFunctions ;
17921812 $ valid_functions ['wp_unslash ' ] = true ;
1793- $ valid_functions ['array_map ' ] = true ;
17941813
17951814 $ functionPtr = $ this ->is_in_function_call ( $ stackPtr , $ valid_functions );
17961815
@@ -1825,11 +1844,11 @@ protected function is_sanitized( $stackPtr, $require_unslash = false ) {
18251844 $ is_unslashed = false ;
18261845 }
18271846
1828- // Arrays might be sanitized via array_map() .
1829- if ( ' array_map ' === $ functionName ) {
1847+ // Arrays might be sanitized via an array walking function using a callback .
1848+ if ( isset ( $ this -> arrayWalkingFunctions [ $ functionName ] ) ) {
18301849
1831- // Get the first parameter.
1832- $ callback = $ this ->get_function_call_parameter ( $ functionPtr , 1 );
1850+ // Get the callback parameter.
1851+ $ callback = $ this ->get_function_call_parameter ( $ functionPtr , $ this -> arrayWalkingFunctions [ $ functionName ] );
18331852
18341853 if ( ! empty ( $ callback ) ) {
18351854 /*
0 commit comments