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.


Built from https://develop.svn.wordpress.org/trunk@47911


git-svn-id: http://core.svn.wordpress.org/trunk@47685 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
whyisjake 2020-06-04 16:43:08 +00:00
parent b013a15d43
commit 00df557404
2 changed files with 20 additions and 5 deletions

View File

@ -629,6 +629,21 @@ abstract class WP_REST_Controller {
$schema = $this->get_item_schema(); $schema = $this->get_item_schema();
$schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array(); $schema_properties = ! empty( $schema['properties'] ) ? $schema['properties'] : array();
$endpoint_args = array(); $endpoint_args = array();
$valid_schema_properties = array(
'type',
'format',
'enum',
'items',
'properties',
'additionalProperties',
'minimum',
'maximum',
'exclusiveMinimum',
'exclusiveMaximum',
'minLength',
'maxLength',
'pattern',
);
foreach ( $schema_properties as $field_id => $params ) { foreach ( $schema_properties as $field_id => $params ) {
@ -654,7 +669,7 @@ abstract class WP_REST_Controller {
$endpoint_args[ $field_id ]['required'] = true; $endpoint_args[ $field_id ]['required'] = true;
} }
foreach ( array( 'type', 'format', 'enum', 'items', 'properties', 'additionalProperties' ) as $schema_prop ) { foreach ( $valid_schema_properties as $schema_prop ) {
if ( isset( $params[ $schema_prop ] ) ) { if ( isset( $params[ $schema_prop ] ) ) {
$endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ]; $endpoint_args[ $field_id ][ $schema_prop ] = $params[ $schema_prop ];
} }

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-alpha-47910'; $wp_version = '5.5-alpha-47911';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.