[wp-trac] [WordPress Trac] #54740: REST API: oneOf validation behaves unexpectedly with strings/arrays
WordPress Trac
noreply at wordpress.org
Tue Jan 4 20:01:59 UTC 2022
#54740: REST API: oneOf validation behaves unexpectedly with strings/arrays
--------------------------+-----------------------------
Reporter: ryelle | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: REST API | Version: 5.6
Severity: normal | Keywords:
Focuses: |
--------------------------+-----------------------------
I'm trying to validate block.json files against
[https://github.com/WordPress/gutenberg/blob/trunk/schemas/json/block.json
the block.json schema], which uses `oneOf` in a few places
([https://github.com/WordPress/gutenberg/blob/b7b62d2d3db4395ce5d2ad42bd1fc0f1c3c2f12d/schemas/json/block.json#L428
for example, "style"]). Using `rest_validate_value_from_schema`, I end up
with this error: "[style] matches more than one of the expected formats.".
I think this is a bug in the validation, because `style` can be one of a
string or an array of strings, but the code that checks the value
(`rest_is_array`) converts the string to an array, forcing it to match
both options.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/54740>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list