[wp-trac] [WordPress Trac] #52932: Rest Api enum validation does not work correctly WordPress 5.7

WordPress Trac noreply at wordpress.org
Sun Mar 28 14:51:05 UTC 2021


#52932: Rest Api enum validation does not work correctly WordPress 5.7
---------------------------+-----------------------
 Reporter:  stefanjoebstl  |       Owner:  (none)
     Type:  defect (bug)   |      Status:  new
 Priority:  normal         |   Milestone:  5.7.1
Component:  REST API       |     Version:  5.7
 Severity:  normal         |  Resolution:
 Keywords:  needs-patch    |     Focuses:  rest-api
---------------------------+-----------------------

Comment (by TimothyBlynJacobs):

 Thanks for the report @stefanjoebstl.

 The issue here is that you are using a `number` type with `integer` values
 for the `enum` cases. This causes the incoming value to be sanitized to
 `1.0`. The results are then compared strictly and `1.0 === 1` will fail in
 PHP.

 You can fix this by specifying your `type` as an `integer`.

 I think, though, we should allow a `number` with a zero fractional part to
 be equivalent to an integer of the same value. @yakimun do you have any
 thoughts on this?

 See #51911.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/52932#comment:2>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list