From 4fb27b070e9ece880eccccf76b1571f5fcd5a0d1 Mon Sep 17 00:00:00 2001 From: Siddharth VP Date: Sat, 28 Jun 2025 15:26:56 +0530 Subject: [PATCH] htmlform: fix min/max validations on empty input in int/float fields Int and float fields that are optional cannot currently specify the min attribute. An unfilled value fails the validation because in PHP 8 any number is greater than the empty string. (For comparing numbers with non-numeric strings, the number is first converted to a string and then compared. In PHP 7, the string was converted to a number instead.) Bug: T397883 Bug: T397643 Change-Id: I37be84554708e17eee27a7e599815891787e95bf (cherry picked from commit 8e7ae749c0870e8133d083ac4125280c11a12ea6) --- includes/htmlform/fields/HTMLFloatField.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/includes/htmlform/fields/HTMLFloatField.php b/includes/htmlform/fields/HTMLFloatField.php index e036fed00ea..6a274325c2e 100644 --- a/includes/htmlform/fields/HTMLFloatField.php +++ b/includes/htmlform/fields/HTMLFloatField.php @@ -20,6 +20,9 @@ class HTMLFloatField extends HTMLTextField { } $value = trim( $value ?? '' ); + if ( $value === '' ) { + return true; + } # https://www.w3.org/TR/html5/infrastructure.html#floating-point-numbers # with the addition that a leading '+' sign is ok.