mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
account for localized floats more robustly.
Normalize floats, strings too, so that they are validated as dddddddddd.dd ref #2853
This commit is contained in:
parent
0a51458ffd
commit
4e0627232c
2 changed files with 11 additions and 7 deletions
|
@ -1660,12 +1660,15 @@ class ValidationTest extends CakeTestCase {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function testDecimalLocaleSet() {
|
public function testDecimalLocaleSet() {
|
||||||
$this->skipIf(DS === '\\', 'The locale is not supported in Windows and affect the others tests.');
|
$this->skipIf(DS === '\\', 'The locale is not supported in Windows and affects other tests.');
|
||||||
$restore = setlocale(LC_NUMERIC, 0);
|
$restore = setlocale(LC_NUMERIC, 0);
|
||||||
$this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available.");
|
$this->skipIf(setlocale(LC_NUMERIC, 'de_DE') === false, "The German locale isn't available.");
|
||||||
|
|
||||||
$this->assertTrue(Validation::decimal(1.54));
|
$this->assertTrue(Validation::decimal(1.54), '1.54 should be considered a valid float');
|
||||||
$this->assertTrue(Validation::decimal('1.54'));
|
$this->assertTrue(Validation::decimal('1.54'), '"1.54" should be considered a valid float');
|
||||||
|
|
||||||
|
$this->assertTrue(Validation::decimal(12345.67), '12345.67 should be considered a valid float');
|
||||||
|
$this->assertTrue(Validation::decimal('12,345.67'), '"12,345.67" should be considered a valid float');
|
||||||
|
|
||||||
setlocale(LC_NUMERIC, $restore);
|
setlocale(LC_NUMERIC, $restore);
|
||||||
}
|
}
|
||||||
|
|
|
@ -426,10 +426,11 @@ class Validation {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Workaround localized floats.
|
// account for localized floats.
|
||||||
if (is_float($check)) {
|
$data = localeconv();
|
||||||
$check = str_replace(',', '.', strval($check));
|
$check = str_replace($data['thousands_sep'], '', $check);
|
||||||
}
|
$check = str_replace($data['decimal_point'], '.', $check);
|
||||||
|
|
||||||
return self::_check($check, $regex);
|
return self::_check($check, $regex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue