Skip to content

Commit dafb5ed

Browse files
authored
Merge pull request #110 from froschdesign/hotfix/isfloat-emptystring
IsFloat validator should return a standard error message for empty strings
2 parents 4f23433 + c42d9e5 commit dafb5ed

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Validator/IsFloat.php

+6
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,12 @@ public function isValid($value)
118118
return true;
119119
}
120120

121+
if ($value === '') {
122+
$this->error(self::NOT_FLOAT);
123+
124+
return false;
125+
}
126+
121127
// Need to check if this is scientific formatted string. If not, switch to decimal.
122128
$formatter = new NumberFormatter($this->getLocale(), NumberFormatter::SCIENTIFIC);
123129

test/Validator/IsFloatTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -217,4 +217,14 @@ public function testNotFloat(): void
217217
$message = $this->validator->getMessages();
218218
self::assertStringContainsString('does not appear to be a float', $message['notFloat']);
219219
}
220+
221+
public function testEmptyStringShouldReturnStandardErrorMessage(): void
222+
{
223+
self::assertFalse($this->validator->isValid(''));
224+
$message = $this->validator->getMessages();
225+
self::assertStringContainsString(
226+
'does not appear to be a float',
227+
$message['notFloat']
228+
);
229+
}
220230
}

0 commit comments

Comments
 (0)