Make WordPress Core


Ignore:
Timestamp:
04/04/2021 06:05:10 PM (3 years ago)
Author:
SergeyBiryukov
Message:

REST API: Correct enum validation for numeric values.

When validating enum values as integer or number, consider a number with a zero fractional part to be equivalent to an integer of the same value.

In rest_are_values_equal(), when comparing two values of type int or float (in any combination), first cast both of them to float and then compare.

This matches some test cases from the official JSON Schema test suite.

Follow-up to [50010].

Props yakimun, stefanjoebstl, TimothyBlynJacobs, rachelbaker.
Fixes #52932.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/rest-api.php

    r50461 r50653  
    19251925
    19261926        return true;
     1927    }
     1928
     1929    if ( is_int( $value1 ) && is_float( $value2 )
     1930        || is_float( $value1 ) && is_int( $value2 )
     1931    ) {
     1932        return (float) $value1 === (float) $value2;
    19271933    }
    19281934
Note: See TracChangeset for help on using the changeset viewer.