Make WordPress Core


Ignore:
Timestamp:
06/04/2020 04:41:47 PM (4 years ago)
Author:
whyisjake
Message:

REST API: Ensure that all properties of get_endpoint_args_for_item_schema are listed.

  • Add new var $valid_schema_properties to match rest_validate_value_from_schema()
  • Unit test to ensure all valid properties exists, and non-valid properties are ignored

Fixes: #50301.
Props: pentatonicfunk, TimothyBlynJacobs.

File:
1 edited

Legend:

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

    r47758 r47911  
    627627    public function get_endpoint_args_for_item_schema( $method = WP_REST_Server::CREATABLE ) {
    628628
    629         $schema            = $this->get_item_schema();
    630         $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
    631         $endpoint_args     = array();
     629        $schema                  = $this->get_item_schema();
     630        $schema_properties       = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
     631        $endpoint_args           = array();
     632        $valid_schema_properties = array(
     633            'type',
     634            'format',
     635            'enum',
     636            'items',
     637            'properties',
     638            'additionalProperties',
     639            'minimum',
     640            'maximum',
     641            'exclusiveMinimum',
     642            'exclusiveMaximum',
     643            'minLength',
     644            'maxLength',
     645            'pattern',
     646        );
    632647
    633648        foreach ( $schema_properties as $field_id => $params ) {
     
    655670            }
    656671
    657             foreach ( array( 'type', 'format', 'enum', 'items', 'properties', 'additionalProperties' ) as $schema_prop ) {
     672            foreach ( $valid_schema_properties as $schema_prop ) {
    658673                if ( isset( $params[ $schema_prop ] ) ) {
    659674                    $endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ];
Note: See TracChangeset for help on using the changeset viewer.