Ticket #34659: 34659.4.diff
File 34659.4.diff, 3.1 KB (added by , 8 years ago) |
---|
-
src/wp-includes/rest-api/class-wp-rest-request.php
828 828 continue; 829 829 } 830 830 831 $ sanitized_value = call_user_func( $attributes['args'][ $key ]['sanitize_callback'],$value, $this, $key );831 $args = array( $value, $this, $key ); 832 832 833 if ( ! empty( $attributes['args'][ $key ][ 'sanitize_callback_args' ] ) && is_numeric( $attributes['args'][ $key ][ 'sanitize_callback_args' ] ) ) { 834 $args = array_slice( $args, 0, $attributes['args'][ $key ][ 'sanitize_callback_args' ] ); 835 } 836 837 $sanitized_value = call_user_func_array( $attributes[ 'args' ][ $key ][ 'sanitize_callback' ], $args ); 838 833 839 if ( is_wp_error( $sanitized_value ) ) { 834 840 $invalid_params[ $key ] = $sanitized_value->get_error_message(); 835 841 } else { … … 893 899 $param = $this->get_param( $key ); 894 900 895 901 if ( null !== $param && ! empty( $arg['validate_callback'] ) ) { 896 $valid_check = call_user_func( $arg['validate_callback'], $param, $this, $key );897 902 903 $args = array( $param, $this, $key ); 904 905 if ( ! empty( $arg[ 'validate_callback_args' ] ) && is_numeric( $arg[ 'validate_callback_args' ] ) ) { 906 $args = array_slice( $args, 0, $arg[ 'validate_callback_args' ] ); 907 } 908 909 $valid_check = call_user_func_array( $arg[ 'validate_callback' ], $args ); 910 898 911 if ( false === $valid_check ) { 899 912 $invalid_params[ $key ] = __( 'Invalid parameter.' ); 900 913 } -
tests/phpunit/tests/rest-api/rest-request.php
342 342 $this->assertEquals( 'rest_invalid_param', $valid->get_error_code() ); 343 343 } 344 344 345 public function test_sanitize_callback_args_number() { 346 $this->request->set_url_params( array( 347 'someinteger' => 'aaa', 348 ) ); 349 350 $this->request->set_attributes( array( 351 'args' => array( 352 'someinteger' => array( 353 'sanitize_callback' => 'is_numeric', 354 'sanitize_callback_args' => 1, 355 ), 356 ) 357 ) ); 358 359 $valid = $this->request->sanitize_params(); 360 $this->assertTrue( $valid ); 361 $this->assertEquals( false, $this->request->get_param( 'someinteger' ), 'Should return false instead of NULL when run through is_numeric' ); 362 } 363 364 public function test_validate_callback_args_number() { 365 $this->request->set_url_params( array( 366 'someinteger' => 'aaa', 367 ) ); 368 369 $this->request->set_attributes( array( 370 'args' => array( 371 'someinteger' => array( 372 'validate_callback' => 'is_numeric', 373 'validate_callback_args' => 1, 374 ), 375 ) 376 ) ); 377 378 $valid = $this->request->has_valid_params(); 379 $this->assertWPError( $valid, 'Should call is_numeric with one argument and fail validation' ); 380 } 381 345 382 public function test_has_valid_params_required_flag() { 346 383 $this->request->set_attributes( array( 347 384 'args' => array(