Ticket #39042: 39042.2.diff
File 39042.2.diff, 2.3 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/class-wp-rest-request.php
818 818 continue; 819 819 } 820 820 foreach ( $this->params[ $type ] as $key => $value ) { 821 // if no sanitize_callback was specified, defaultto rest_parse_request_arg821 // Determine if we should fallback to rest_parse_request_arg 822 822 // if a type was specified in the args. 823 823 if ( ! isset( $attributes['args'][ $key ]['sanitize_callback'] ) && ! empty( $attributes['args'][ $key ]['type'] ) ) { 824 $attributes['args'][ $key ]['sanitize_callback'] = 'rest_parse_request_arg'; 824 // Bypass if the callback is null or false. 825 if ( ! array_key_exists( 'sanitize_callback', $attributes['args'][ $key ] ) ) { 826 $attributes['args'][ $key ]['sanitize_callback'] = 'rest_parse_request_arg'; 827 } 825 828 } 826 829 // Check if this param has a sanitize_callback added. 827 830 if ( ! isset( $attributes['args'][ $key ] ) || empty( $attributes['args'][ $key ]['sanitize_callback'] ) ) { -
tests/phpunit/tests/rest-api/rest-request.php
342 342 $this->assertEquals( 'rest_invalid_param', $valid->get_error_code() ); 343 343 } 344 344 345 /** 346 * @ticket 39042 347 */ 348 public function test_sanitize_params_with_null_callback() { 349 $this->request->set_url_params( array( 350 'some_email' => '', 351 'some_uri' => 1.23422, 352 )); 353 354 $this->request->set_attributes( array( 355 'args' => array( 356 'some_email' => array( 357 'type' => 'string', 358 'format' => 'email', 359 'sanitize_callback' => null, 360 ), 361 'some_uri' => array( 362 'type' => 'string', 363 'format' => 'uri', 364 'sanitize_callback' => false, 365 ), 366 ), 367 )); 368 369 $result = $this->request->sanitize_params(); 370 $this->assertEquals( true, $result ); 371 } 372 345 373 public function test_has_valid_params_required_flag() { 346 374 $this->request->set_attributes( array( 347 375 'args' => array(