diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 336fe6b071..0121e063f7 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -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; } diff --git a/tests/phpunit/tests/rest-api/rest-schema-validation.php b/tests/phpunit/tests/rest-api/rest-schema-validation.php index 6eb6c423d3..2fab13fe0a 100644 --- a/tests/phpunit/tests/rest-api/rest-schema-validation.php +++ b/tests/phpunit/tests/rest-api/rest-schema-validation.php @@ -250,6 +250,7 @@ class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { /** * @ticket 51911 + * @ticket 52932 * * @dataProvider data_different_types_of_value_and_enum_elements * @@ -304,6 +305,14 @@ class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { ), true, ), + array( + 1, + array( + 'type' => 'integer', + 'enum' => array( 0.0, 1.0 ), + ), + true, + ), array( 1.0, array( @@ -378,6 +387,14 @@ class WP_Test_REST_Schema_Validation extends WP_UnitTestCase { ), true, ), + array( + 1, + array( + 'type' => 'number', + 'enum' => array( 0, 1 ), + ), + true, + ), array( 1.0, array(