symfony/symfony — Issue #3124: [FormType] MoneyType regexp broken for JPY
Author: ma2thieu
Created: 2012-01-16 14:19:03+00:00
State: open

The regexp in MoneyType doesn't work if currency format has no decimal (like JPY) and doesn't work either if the currency symbol is unicode
the following patch should fix both problems :

===================================================================
--- vendor/symfony/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php	(revision )
+++ vendor/symfony/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php	(revision )
@@ -100,7 +100,7 @@

// the regex also considers non-break spaces (0xC2 or 0xA0 in UTF-8)

- preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123[,.]00[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/', $pattern, $matches);
+ preg_match('/^([^\s\xc2\xa0]*)[\s\xc2\xa0]*123[,.]*[0]*[\s\xc2\xa0]*([^\s\xc2\xa0]*)$/u', $pattern, $matches);

if (!empty($matches[1])) {
self::$patterns[\Locale::getDefault()] = $matches[1].' {{ widget }}';