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.
Built from https://develop.svn.wordpress.org/trunk@50653


git-svn-id: http://core.svn.wordpress.org/trunk@50265 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2021-04-04 18:07:04 +00:00
parent 907bfe74cd
commit b6e32b9d4f
2 changed files with 7 additions and 1 deletions

View File

@ -1926,6 +1926,12 @@ function rest_are_values_equal( $value1, $value2 ) {
return true;
}
if ( is_int( $value1 ) && is_float( $value2 )
|| is_float( $value1 ) && is_int( $value2 )
) {
return (float) $value1 === (float) $value2;
}
return $value1 === $value2;
}

View File

@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.8-alpha-50652';
$wp_version = '5.8-alpha-50653';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.