mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
Treat float numbers with trailing zeroes removed by PHP, accordingly.
Revert #2800 (28bd6880df
) regex changes. Also add more tests.
Signed-off-by: mark_story <mark@mark-story.com>
This commit is contained in:
parent
f06ce1324d
commit
b75a6b440a
2 changed files with 12 additions and 5 deletions
|
@ -1498,16 +1498,20 @@ class ValidationTest extends CakeTestCase {
|
|||
$this->assertTrue(Validation::decimal('+0123.45e6'));
|
||||
$this->assertTrue(Validation::decimal('-0123.45e6'));
|
||||
$this->assertTrue(Validation::decimal('0123.45e6'));
|
||||
$this->assertTrue(Validation::decimal('1234'));
|
||||
$this->assertTrue(Validation::decimal('-1234'));
|
||||
$this->assertTrue(Validation::decimal('+1234'));
|
||||
$this->assertTrue(Validation::decimal(1234.56));
|
||||
$this->assertTrue(Validation::decimal(1234.00));
|
||||
$this->assertTrue(Validation::decimal('1234.00'));
|
||||
$this->assertTrue(Validation::decimal(.0));
|
||||
$this->assertTrue(Validation::decimal(.00));
|
||||
$this->assertTrue(Validation::decimal('.00'));
|
||||
$this->assertTrue(Validation::decimal(.01));
|
||||
$this->assertTrue(Validation::decimal('.01'));
|
||||
|
||||
$this->assertFalse(Validation::decimal(''));
|
||||
$this->assertFalse(Validation::decimal('string'));
|
||||
$this->assertFalse(Validation::decimal('1234'));
|
||||
$this->assertFalse(Validation::decimal('-1234'));
|
||||
$this->assertFalse(Validation::decimal('+1234'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -381,11 +381,14 @@ class Validation {
|
|||
* @return boolean Success
|
||||
*/
|
||||
public static function decimal($check, $places = null, $regex = null) {
|
||||
if (is_float($check) && floor($check) === $check) {
|
||||
$check = sprintf("%.1f", $check);
|
||||
}
|
||||
if (is_null($regex)) {
|
||||
if (is_null($places)) {
|
||||
$regex = '/^[-+]?[0-9]*(\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?)?$/';
|
||||
$regex = '/^[-+]?[0-9]*\\.{1}[0-9]+(?:[eE][-+]?[0-9]+)?$/';
|
||||
} else {
|
||||
$regex = '/^[-+]?[0-9]*(\\.{1}[0-9]{' . $places . '})?$/';
|
||||
$regex = '/^[-+]?[0-9]*\\.{1}[0-9]{' . $places . '}$/';
|
||||
}
|
||||
}
|
||||
return self::_check($check, $regex);
|
||||
|
|
Loading…
Add table
Reference in a new issue