[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
Tue Dec 4 10:47:10 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        |  Resolution:
 Keywords:  has-patch     |     Focuses:  rest-api
--------------------------+------------------------------

Comment (by birgire):

 @wpboss I had a look at {{{preg_split()}}} and stumpled upon an
 interesting comment here:

 https://secure.php.net/manual/en/function.preg-split.php#121475

 that {{{null}}} input for the limit will generate an error in
 {{{strict_type}}} mode in PHP 7.1+

 I could verify that with this snippet in PHP 7.1:

 {{{
 <?php
 declare(strict_types=1);
 $value = null;
 $value = preg_split( '/[\s,]+/', $value, null, PREG_SPLIT_NO_EMPTY );
 var_dump( $value );
 }}}

 So instead of

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

 it looks like one could consider:

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

 as already used elsewhere in core.

 > I have fixed this and test it.

 @wpboss I guess you mean manually tested it. It would also be interesting
 to check if the current unit tests for
 {{{rest_sanitize_value_from_schema()}}} and the restapi group will run
 successfully.

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


More information about the wp-trac mailing list