#51911 closed enhancement (fixed)
REST API: Make JSON Schema enum more robust for non-string types
Reported by: |
|
Owned by: |
|
---|---|---|---|
Milestone: | 5.7 | Priority: | normal |
Severity: | normal | Version: | 4.7 |
Component: | REST API | Keywords: | good-first-bug json-schema has-patch has-unit-tests |
Focuses: | Cc: |
Description
The enum
JSON schema keyword allows for enforcing that the provided value is one of the listed values. This can be used with any type of value. Our implementation, however, doesn't apply the same type coercion when doing regular validation.
In other words, for an enum of [ 0, 1 ]
I should be able to pass "1"
.
To do this, I think we might want to move the enum
validation to the end of rest_validate_value_from_schema
so that type validation has already been applied, and then either call rest_sanitize_value_from_schema
before passing the value to the enum
check, or just do the type casting.
We'll also need to pay special care to arrays/objects applying rest_stabilize_value
and making sure that the type safe in_array()
check has the correct JSON semantics.
Change History (4)
This ticket was mentioned in PR #912 on WordPress/wordpress-develop by yakimun.
4 years ago
#1
- Keywords has-patch has-unit-tests added; needs-patch removed
#3
@
4 years ago
- Owner set to TimothyBlynJacobs
- Resolution set to fixed
- Status changed from new to closed
In 50010:
TimothyBJacobs commented on PR #912:
4 years ago
#4
Merged in https://github.com/WordPress/wordpress-develop/commit/0ceee0f871ac442f38e871b889eb6b77b611b487. Thanks for your great work on this @yakimun!
Added support for type coercion in enum JSON Schema keyword.
Trac ticket: https://core.trac.wordpress.org/ticket/51911