Ticket #38720: 38720.diff
File 38720.diff, 2.9 KB (added by , 7 years ago) |
---|
-
src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php
diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 2b7057c..1021cc2 100644
a b class WP_REST_Comments_Controller extends WP_REST_Controller { 431 431 } 432 432 433 433 /* 434 * Do not allow a comment to be created with an empty string for434 * Do not allow a comment to be created with missing or empty 435 435 * comment_content. See wp_handle_comment_submission(). 436 436 */ 437 if ( '' === $prepared_comment['comment_content']) {438 return new WP_Error( 'rest_comment_content_ invalid', __( 'Comment content is invalid.' ), array( 'status' => 400 ) );437 if ( empty( $prepared_comment['comment_content'] ) ) { 438 return new WP_Error( 'rest_comment_content_required', __( 'Missing comment content.' ), array( 'status' => 400 ) ); 439 439 } 440 440 441 441 // Setting remaining values before wp_insert_comment so we can use wp_allow_comment(). … … class WP_REST_Comments_Controller extends WP_REST_Controller { 1064 1064 } 1065 1065 } 1066 1066 1067 // Require 'comment_content' unless only the 'comment_status' is being updated.1068 if ( ! empty( $prepared_comment ) && ! isset( $prepared_comment['comment_content'] ) ) {1069 return new WP_Error( 'rest_comment_content_required', __( 'Missing comment content.' ), array( 'status' => 400 ) );1070 }1071 1072 1067 /** 1073 1068 * Filters a comment after it is prepared for the database. 1074 1069 * -
tests/phpunit/tests/rest-api/rest-comments-controller.php
diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index e225cbc..895a91a 100644
a b class WP_Test_REST_Comments_Controller extends WP_Test_REST_Controller_Testcase 827 827 $this->assertEquals( self::$post_id, $data['post'] ); 828 828 } 829 829 830 public function test_create_item_no_content() { 831 wp_set_current_user( 0 ); 832 833 $params = array( 834 'post' => self::$post_id, 835 'author_name' => 'Comic Book Guy', 836 'author_email' => 'cbg@androidsdungeon.com', 837 'author_url' => 'http://androidsdungeon.com', 838 'content' => '', 839 'date' => '2014-11-07T10:14:25', 840 ); 841 842 $request = new WP_REST_Request( 'POST', '/wp/v2/comments' ); 843 $request->add_header( 'content-type', 'application/json' ); 844 $request->set_body( wp_json_encode( $params ) ); 845 $response = $this->server->dispatch( $request ); 846 $this->assertErrorResponse( 'rest_comment_content_required', $response, 400 ); 847 848 unset( $params['content'] ); 849 $request->set_body( wp_json_encode( $params ) ); 850 $response = $this->server->dispatch( $request ); 851 $this->assertErrorResponse( 'rest_comment_content_required', $response, 400 ); 852 } 853 830 854 public function test_create_item_using_accepted_content_raw_value() { 831 855 wp_set_current_user( 0 ); 832 856