Make WordPress Core


Ignore:
Timestamp:
10/24/2020 10:44:38 PM (6 years ago)
Author:
TimothyBlynJacobs
Message:

REST API, XML-RPC: Synchronise empty comment content checks.

The REST API and XML-RPC now uses the same detection methodology for empty comment content as wp_handle_comment_submission(). Specifically, comments now have their content trimmed and '0' is allowed.

Props jaswrks, rmccue, dd32, rachelbaker, Cawa-93, aduth, TimothyBlynJacobs.
Fixes #43177.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tests/phpunit/tests/xmlrpc/wp/newComment.php

    r49271 r49303  
    5151        }
    5252
     53        /**
     54         * @ticket 43177
     55         */
     56        public function test_empty_content_multiple_spaces() {
     57                $result = $this->myxmlrpcserver->wp_newComment(
     58                        array(
     59                                1,
     60                                'administrator',
     61                                'administrator',
     62                                self::$post->ID,
     63                                array(
     64                                        'content' => '   ',
     65                                ),
     66                        )
     67                );
     68
     69                $this->assertIXRError( $result );
     70                $this->assertSame( 403, $result->code );
     71        }
     72
     73        /**
     74         * @ticket 43177
     75         */
     76        public function test_valid_comment_0_content() {
     77                $result = $this->myxmlrpcserver->wp_newComment(
     78                        array(
     79                                1,
     80                                'administrator',
     81                                'administrator',
     82                                self::$post->ID,
     83                                array(
     84                                        'content' => '0',
     85                                ),
     86                        )
     87                );
     88
     89                $this->assertNotIXRError( $result );
     90        }
     91
     92        /**
     93         * @ticket 43177
     94         */
     95        public function test_valid_comment_allow_empty_content() {
     96                add_filter( 'allow_empty_comment', '__return_true' );
     97                $result = $this->myxmlrpcserver->wp_newComment(
     98                        array(
     99                                1,
     100                                'administrator',
     101                                'administrator',
     102                                self::$post->ID,
     103                                array(
     104                                        'content' => '   ',
     105                                ),
     106                        )
     107                );
     108
     109                $this->assertNotIXRError( $result );
     110        }
     111
    53112        function test_new_comment_post_closed() {
    54113                $post = self::factory()->post->create_and_get(
Note: See TracChangeset for help on using the changeset viewer.