diff --git a/src/Validator/IsFloat.php b/src/Validator/IsFloat.php index 0e662693..6c142563 100644 --- a/src/Validator/IsFloat.php +++ b/src/Validator/IsFloat.php @@ -118,6 +118,12 @@ public function isValid($value) return true; } + if ($value === '') { + $this->error(self::NOT_FLOAT); + + return false; + } + // Need to check if this is scientific formatted string. If not, switch to decimal. $formatter = new NumberFormatter($this->getLocale(), NumberFormatter::SCIENTIFIC); diff --git a/test/Validator/IsFloatTest.php b/test/Validator/IsFloatTest.php index 88cead26..8a740804 100644 --- a/test/Validator/IsFloatTest.php +++ b/test/Validator/IsFloatTest.php @@ -217,4 +217,14 @@ public function testNotFloat(): void $message = $this->validator->getMessages(); self::assertStringContainsString('does not appear to be a float', $message['notFloat']); } + + public function testEmptyStringShouldReturnStandardErrorMessage(): void + { + self::assertFalse($this->validator->isValid('')); + $message = $this->validator->getMessages(); + self::assertStringContainsString( + 'does not appear to be a float', + $message['notFloat'] + ); + } }