REST API: Allow schema sanitization_callback to be set to null to bypass fallback sanitization functions.

The logic in WP_REST_Request->sanitize_params() added in [39091] did not account for `null` or `false` being the sanitization_callback preventing overriding `rest_parse_request_arg()`. This fixes that oversight, allowing the built in sanitization function to be bypassed. See #38593.

Props kkoppenhaver, rachelbaker, jnylen0.
Fixes #39042.


git-svn-id: https://develop.svn.wordpress.org/trunk@39563 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Rachel Baker
2016-12-11 21:25:40 +00:00
parent 3a3ebc76a3
commit 260a88d009
2 changed files with 47 additions and 7 deletions

View File

@@ -342,6 +342,42 @@ class Tests_REST_Request extends WP_UnitTestCase {
$this->assertEquals( 'rest_invalid_param', $valid->get_error_code() );
}
public function test_sanitize_params_with_null_callback() {
$this->request->set_url_params( array(
'some_email' => '',
) );
$this->request->set_attributes( array(
'args' => array(
'some_email' => array(
'type' => 'string',
'format' => 'email',
'sanitize_callback' => null,
),
),
) );
$this->assertTrue( $this->request->sanitize_params() );
}
public function test_sanitize_params_with_false_callback() {
$this->request->set_url_params( array(
'some_uri' => 1.23422,
) );
$this->request->set_attributes( array(
'args' => array(
'some_uri' => array(
'type' => 'string',
'format' => 'uri',
'sanitize_callback' => false,
),
),
) );
$this->assertTrue( $this->request->sanitize_params() );
}
public function test_has_valid_params_required_flag() {
$this->request->set_attributes( array(
'args' => array(