[wp-trac] [WordPress Trac] #50300: Multi type on args properties returning invalid error message when not validated

WordPress Trac noreply at wordpress.org
Tue Jun 2 05:14:23 UTC 2020


#50300: Multi type on args properties returning invalid error message when not
validated
----------------------------+-----------------------------
 Reporter:  pentatonicfunk  |      Owner:  (none)
     Type:  defect (bug)    |     Status:  new
 Priority:  normal          |  Milestone:  Awaiting Review
Component:  REST API        |    Version:  5.4.1
 Severity:  normal          |   Keywords:
  Focuses:  rest-api        |
----------------------------+-----------------------------
 I was able to reproduce it only on specific case when type being used are
 `null` '''AND''' `integer`, `AND` specify `minimum` & `maximum`. But its
 probably the case too when using `exclusiveMinimum` or `exclusiveMaximum`

 === Test Case
 {{{#!php
 <?php

 $request = new WP_REST_Request();
 $request->set_attributes(
     array(
         'args' => array(
             'null_or_integer' => array(
                 'type'    => array( 'null', 'integer' ),
                 'minimum' => 10,
                 'maximum' => 20,
             ),
         ),
     )
 );

 $param    = 'null_or_integer';
 $value    = 1;
 $is_valid = rest_validate_request_arg( $value, $request, $param );

 print_r( $is_valid->get_error_message() );

 }}}

 === Expected
 ''null_or_integer must be between 10 (inclusive) and 20.''

 === Actual
 ''null_or_integer is not of type null,integer.''
 Which isn't true, since `value` passed was integer.

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


More information about the wp-trac mailing list