[wp-trac] [WordPress Trac] #51911: REST API: Make JSON Schema enum more robust for non-string types

WordPress Trac noreply at wordpress.org
Tue Dec 1 21:12:53 UTC 2020


#51911: REST API: Make JSON Schema enum more robust for non-string types
-------------------------+-------------------------------------------------
 Reporter:               |      Owner:  (none)
  TimothyBlynJacobs      |
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Future Release
Component:  REST API     |    Version:  4.7
 Severity:  normal       |   Keywords:  needs-patch good-first-bug json-
  Focuses:               |  schema
-------------------------+-------------------------------------------------
 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.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/51911>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list