Skip to content

Commit

Permalink
Fix deep sanitization of arrays, fixes issue with GROUPINGS (and othe…
Browse files Browse the repository at this point in the history
…r array structures) not being sent.
  • Loading branch information
dannyvankooten committed May 30, 2015
1 parent a9a5b5a commit d8cab36
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions includes/class-request.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ protected function normalize_data( array $data ) {
$data = stripslashes_deep( $data );

// sanitize all scalar values
$data = $this->sanitize_data_array( $data );
$data = $this->sanitize_deep( $data );

/**
* @filter `mc4wp_form_data`
Expand All @@ -109,22 +109,24 @@ protected function normalize_data( array $data ) {
}

/**
* @param $dirty
* @param $value
*
* @return array
* @return array|string
*/
public function sanitize_data_array( $dirty ) {
$clean = array();

foreach( $dirty as $field => $value ) {
if ( is_scalar( $value ) ) {
$clean[ $field ] = sanitize_text_field( $value );
} elseif( is_array( $value ) ) {
$clean[ $field ] = array_map( array( $this, 'sanitize_data_array' ), $value );
public function sanitize_deep( $value ) {

if ( is_scalar( $value ) ) {
$value = sanitize_text_field( $value );
} elseif( is_array( $value ) ) {
$value = array_map( array( $this, 'sanitize_deep' ), $value );
} elseif ( is_object($value) ) {
$vars = get_object_vars( $value );
foreach ($vars as $key=>$data) {
$value->{$key} = $this->sanitize_deep( $data );
}
}

return $clean;
return $value;
}

/**
Expand Down

0 comments on commit d8cab36

Please sign in to comment.