From fafc4d447c2f9efd0a4d99aa1e8c7999bf9bbb03 Mon Sep 17 00:00:00 2001 From: Gautam Mehta Date: Wed, 20 May 2026 08:34:28 +0530 Subject: [PATCH 1/4] fix: rest_is_integer validation logic --- src/wp-includes/rest-api.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 5548ecf5c6f45..5e3b1a8d50b39 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -1570,7 +1570,20 @@ function rest_is_boolean( $maybe_bool ) { * @return bool True if an integer, otherwise false. */ function rest_is_integer( $maybe_integer ) { - return is_numeric( $maybe_integer ) && round( (float) $maybe_integer ) === (float) $maybe_integer; + if ( is_int( $maybe_integer ) ) { + return true; + } + + if ( ! is_scalar( $maybe_integer ) ) { + return false; + } + + $integer_pattern = '/^[+-]?\d+$/'; + + return preg_match( + $integer_pattern, + trim( (string) $maybe_integer ) + ) === 1; } /** From b3f5da361acdb13be6ab79e2e72d168ddb2a9b24 Mon Sep 17 00:00:00 2001 From: Gautam Mehta Date: Wed, 20 May 2026 08:57:20 +0530 Subject: [PATCH 2/4] phpcs: improve formatting --- src/wp-includes/rest-api.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 5e3b1a8d50b39..2304210956a5b 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -1581,9 +1581,9 @@ function rest_is_integer( $maybe_integer ) { $integer_pattern = '/^[+-]?\d+$/'; return preg_match( - $integer_pattern, - trim( (string) $maybe_integer ) - ) === 1; + $integer_pattern, + trim( (string) $maybe_integer ) + ) === 1; } /** From 8ba541f27317abfa8f6d18964885ea89896dca90 Mon Sep 17 00:00:00 2001 From: Gautam Mehta Date: Thu, 21 May 2026 10:27:28 +0530 Subject: [PATCH 3/4] feat: add scientific notation in validation scope --- src/wp-includes/rest-api.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index 2304210956a5b..e3d4dddcac153 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -1578,12 +1578,20 @@ function rest_is_integer( $maybe_integer ) { return false; } - $integer_pattern = '/^[+-]?\d+$/'; + $integer_pattern = '/^[+-]?\d+$/'; + $scientific_pattern = '/^[+-]?\d+e\+?\d+$/i'; - return preg_match( - $integer_pattern, - trim( (string) $maybe_integer ) - ) === 1; + $value = trim( (string) $maybe_integer ); + + if ( preg_match( $integer_pattern, $value ) ) { + return true; + } + + if ( preg_match( $scientific_pattern, $value ) ) { + return true; + } + + return false; } /** From 4ac1ff741cdf88cf4ba693eda248efbbb85f4bb0 Mon Sep 17 00:00:00 2001 From: Gautam Mehta Date: Thu, 21 May 2026 19:59:57 +0530 Subject: [PATCH 4/4] fix: handle boolean values correctly --- src/wp-includes/rest-api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api.php b/src/wp-includes/rest-api.php index e3d4dddcac153..dcd090c715dbe 100644 --- a/src/wp-includes/rest-api.php +++ b/src/wp-includes/rest-api.php @@ -1574,7 +1574,7 @@ function rest_is_integer( $maybe_integer ) { return true; } - if ( ! is_scalar( $maybe_integer ) ) { + if ( is_bool( $maybe_integer ) || ! is_scalar( $maybe_integer ) ) { return false; }