From 551b6260da7c374bdfdeb2f42a99a80979517ac5 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Sun, 4 Apr 2021 19:13:03 +0000 Subject: [PATCH] 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. Merges [50653] to the 5.7 branch. Fixes #52932. Built from https://develop.svn.wordpress.org/branches/5.7@50656 git-svn-id: http://core.svn.wordpress.org/branches/5.7@50268 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/rest-api.php | 6 ++++++ wp-includes/version.php | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/wp-includes/rest-api.php b/wp-includes/rest-api.php index 4ca0ae7cb0..49eb1bbfd4 100644 --- a/wp-includes/rest-api.php +++ b/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/wp-includes/version.php b/wp-includes/version.php index 90c6fe705f..8edc841b77 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -13,7 +13,7 @@ * * @global string $wp_version */ -$wp_version = '5.7.1-alpha-50655'; +$wp_version = '5.7.1-alpha-50656'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.