Make WordPress Core

Changeset 64437


Ignore:
Timestamp:
10/17/2026 04:17:30 PM (5 days ago)
Author:
jorgefilipecosta
Message:

REST API: Correct the action-unfiltered-html link's target schema.

The target schema of the https://api.w.org/action-unfiltered-html link description object nested raw directly under content, without the type and properties keywords. raw isn't a JSON Schema keyword, so the schema put no constraint on content.
Wraps raw in an object schema, like the content property of the post schema, and adds a test for it.

Developed in ​https://github.com/WordPress/wordpress-develop/pull/14362.

Follow-up to [43974].

Props jorgefilipecosta.
Fixes #66332.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php

    r64433 r64437  
    29012901                                'properties' => array(
    29022902                                        'content' => array(
    2903                                                 'raw' => array(
    2904                                                         'type' => 'string',
     2903                                                'type'       => 'object',
     2904                                                'properties' => array(
     2905                                                        'raw' => array(
     2906                                                                'type' => 'string',
     2907                                                        ),
    29052908                                                ),
    29062909                                        ),
  • trunk/tests/phpunit/tests/rest-api/rest-posts-controller.php

    r64343 r64437  
    52085208        }
    52095209
     5210        /**
     5211         * @ticket 66332
     5212         *
     5213         * @covers WP_REST_Posts_Controller::get_schema_links
     5214         */
     5215        public function test_unfiltered_html_action_ldo_target_schema() {
     5216                $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) );
     5217                $data     = $response->get_data();
     5218                $schema   = $data['schema'];
     5219
     5220                $this->assertArrayHasKey( 'links', $schema, 'The schema should have links.' );
     5221                $unfiltered_html = wp_list_filter( $schema['links'], array( 'rel' => 'https://api.w.org/action-unfiltered-html' ) );
     5222
     5223                $this->assertCount( 1, $unfiltered_html, 'The action-unfiltered-html LDO should be on the schema once.' );
     5224
     5225                $ldo = array_shift( $unfiltered_html );
     5226
     5227                $this->assertSame(
     5228                        array(
     5229                                'type'       => 'object',
     5230                                'properties' => array(
     5231                                        'content' => array(
     5232                                                'type'       => 'object',
     5233                                                'properties' => array(
     5234                                                        'raw' => array(
     5235                                                                'type' => 'string',
     5236                                                        ),
     5237                                                ),
     5238                                        ),
     5239                                ),
     5240                        ),
     5241                        $ldo['targetSchema'],
     5242                        'The target schema should describe content.raw as a string.'
     5243                );
     5244        }
     5245
    52105246        public function test_sticky_action_ldo_registered_for_posts() {
    52115247                $response = rest_get_server()->dispatch( new WP_REST_Request( 'OPTIONS', '/wp/v2/posts' ) );
Note: See TracChangeset for help on using the changeset viewer.