diff --git a/typo3/sysext/form/Classes/Domain/Filter/CurrencyFilter.php b/typo3/sysext/form/Classes/Domain/Filter/CurrencyFilter.php index c55668609409a9462b143ffc3b42da7cd285bee8..94d2da8bd5770a2fd4ddc5e85aefebb33063bbcb 100644 --- a/typo3/sysext/form/Classes/Domain/Filter/CurrencyFilter.php +++ b/typo3/sysext/form/Classes/Domain/Filter/CurrencyFilter.php @@ -89,7 +89,21 @@ class CurrencyFilter extends AbstractFilter implements FilterInterface */ public function filter($value) { - $value = (double) ((string)$value); + $value = str_replace( + array( + $this->thousandSeparator, + $this->decimalsPoint, + ), + array( + '', + '.' + ), + (string)$value + ); + + // replace all non numeric characters, decimalPoint and negativ sign + $value = preg_replace("/[^0-9.-]/", "", $value); + $value = (double)$value; return number_format($value, 2, $this->decimalsPoint, $this->thousandSeparator); } } diff --git a/typo3/sysext/form/Tests/Unit/Filter/CurrencyFilterTest.php b/typo3/sysext/form/Tests/Unit/Filter/CurrencyFilterTest.php index 2bd6198aab7bf4a9fc973115fada6d4f486a6aa1..9cf49fc96cec171f80080c08576eb19b73115ada 100644 --- a/typo3/sysext/form/Tests/Unit/Filter/CurrencyFilterTest.php +++ b/typo3/sysext/form/Tests/Unit/Filter/CurrencyFilterTest.php @@ -33,29 +33,59 @@ class CurrencyFilterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase { return array( '1200 => 1.200,00' => array( - 1200, // input + '1200', // input '.', // thousand separator ',', // decimal point '1.200,00' // expected ), '0 => 0,00' => array( - 0, + '0', null, ',', '0,00' ), '3333.33 => 3,333.33' => array( - 3333.33, + '3333.33', ',', '.', '3,333.33' ), '1099.33 => 1 099,33' => array( - 1099.33, + '1099.33', ' ', ',', '1 099,33' ), + '1200,00 => 1.200,00' => array( + '1200,00', // input + '.', // thousand separator + ',', // decimal point + '1.200,00' // expected + ), + '1.200,00 => 1.200,00' => array( + '1.200,00', // input + '.', // thousand separator + ',', // decimal point + '1.200,00' // expected + ), + '1.200 => 1.200,00' => array( + '1.200', // input + '.', // thousand separator + ',', // decimal point + '1.200,00' // expected + ), + '-1 => -1,00' => array( + '-1', // input + '.', // thousand separator + ',', // decimal point + '-1,00' // expected + ), + '1.200 => 1.200,00' => array( + '1.200', // input + '.', // thousand separator + ',', // decimal point + '1.200,00' // expected + ), ); }