[wp-trac] [WordPress Trac] #45448: rest_sanitize_value_from_schema() returns invalid value when using a schema of type array with a null value

WordPress Trac noreply at wordpress.org
Thu Nov 29 17:37:21 UTC 2018


#45448: rest_sanitize_value_from_schema() returns invalid value when using a schema
of type array with a null value
--------------------------+-----------------------------
 Reporter:  hogash        |      Owner:  (none)
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  REST API      |    Version:  4.9.8
 Severity:  normal        |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 When using the following configuration, you will get an array containing 1
 empty string instead of an empty array;
 {{{
 $schema = array(
         'type'  => 'array',
         'items' => [
                 'type' => 'string',
         ],
 );

 $value = rest_sanitize_value_from_schema( null, $schema );
 var_dump( $value );
 }}}

 The solution for this would be to modify the following line in
 rest_sanitize_value_from_schema():

 {{{
 $value = preg_split( '/[\s,]+/', $value );
 }}}

 with

 {{{
 $value = preg_split( '/[\s,]+/', $value, null, PREG_SPLIT_NO_EMPTY );
 }}}

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/45448>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list