Repository navigation
Conversation
…erties schemas. Previously, `rest_validate_object_value_from_schema()` called `rest_find_matching_pattern_property_schema()`, which returns only the first matching pattern's schema. As a result, a property matching multiple `patternProperties` patterns could pass validation even when failing a later pattern's constraints, making validation order-dependent and inconsistent with JSON Schema draft 4. Iterate through all `patternProperties` in `rest_validate_object_value_from_schema()` and validate the property value against every matching pattern's schema, while leaving `rest_find_matching_pattern_property_schema()`'s public signature and return contract unchanged for backwards compatibility. Trac ticket: https://core.trac.wordpress.org/ticket/66871
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Trac ticket: https://core.trac.wordpress.org/ticket/66871
Description
rest_validate_object_value_from_schema()previously calledrest_find_matching_pattern_property_schema(), which returns only the first matchingpatternPropertiesschema. As a result, a property matching multiple patterns could pass validation even when it violated a subsequent matching pattern's constraints, making validation order-dependent and inconsistent with JSON Schema draft 4.Changes
rest_validate_object_value_from_schema()(src/wp-includes/rest-api.php), iterate over all entries in$args['patternProperties']and validate the property value against every matching pattern's schema.rest_find_matching_pattern_property_schema()'s public signature andarray|nullreturn contract for backwards compatibility with existing callers (rest_sanitize_value_from_schema(),rest_filter_response_by_context(), and third-party code).propertiesprecedence ([49082]/ #51024) andadditionalPropertiesfallback when no pattern matches.tests/phpunit/tests/rest-api/rest-schema-validation.phpcovering multiple matching patterns, pattern-order independence, conflicting type constraints, single-pattern matches, andadditionalProperties: falsefallback.Testing
vendor/bin/phpcson both modified files.WP_Test_REST_Schema_ValidationandWP_Test_REST_Schema_Sanitization(258 tests, 454 assertions) and multisite PHPUnit onWP_Test_REST_Schema_Validation(217 tests, 339 assertions).