diff --git src/wp-includes/rest-api/class-wp-rest-request.php src/wp-includes/rest-api/class-wp-rest-request.php
index 3c465babd..0022eae7e 100644
|
|
|
class WP_REST_Request implements ArrayAccess { |
| 669 | 669 | return true; |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | | $params = json_decode( $this->get_body(), true ); |
| | 672 | // Allow an empty body. See https://core.trac.wordpress.org/ticket/39150. |
| | 673 | $body = $this->get_body(); |
| | 674 | if ( empty( $body ) ) { |
| | 675 | return true; |
| | 676 | } |
| | 677 | |
| | 678 | $params = json_decode( $body, true ); |
| 673 | 679 | |
| 674 | 680 | /* |
| 675 | 681 | * Check for a parsing error. |
diff --git tests/phpunit/tests/rest-api/rest-request.php tests/phpunit/tests/rest-api/rest-request.php
index de44844bf..5d9f2e1fc 100644
|
|
|
|
| 10 | 10 | * @group restapi |
| 11 | 11 | */ |
| 12 | 12 | class Tests_REST_Request extends WP_UnitTestCase { |
| | 13 | |
| | 14 | /** @var WP_REST_Request */ |
| | 15 | public $request; |
| | 16 | |
| 13 | 17 | public function setUp() { |
| 14 | 18 | parent::setUp(); |
| 15 | 19 | |
| … |
… |
class Tests_REST_Request extends WP_UnitTestCase { |
| 414 | 418 | $this->assertEquals( JSON_ERROR_SYNTAX, $data['json_error_code'] ); |
| 415 | 419 | } |
| 416 | 420 | |
| | 421 | |
| | 422 | public function test_has_valid_params_empty_json_no_error() { |
| | 423 | if ( version_compare( PHP_VERSION, '5.3', '<' ) ) { |
| | 424 | return $this->markTestSkipped( 'JSON validation is only available for PHP 5.3+' ); |
| | 425 | } |
| | 426 | |
| | 427 | $this->request->set_header( 'Content-Type', 'application/json' ); |
| | 428 | $this->request->set_body( '' ); |
| | 429 | |
| | 430 | $valid = $this->request->has_valid_params(); |
| | 431 | $this->assertNotWPError( $valid ); |
| | 432 | } |
| | 433 | |
| 417 | 434 | public function test_has_multiple_invalid_params_validate_callback() { |
| 418 | 435 | $this->request->set_url_params( array( |
| 419 | 436 | 'someinteger' => '123', |