diff --git a/src/Symfony/Bridge/Twig/Extension/FormExtension.php b/src/Symfony/Bridge/Twig/Extension/FormExtension.php index e101704efaa9d..ab7c6ab626d8c 100644 --- a/src/Symfony/Bridge/Twig/Extension/FormExtension.php +++ b/src/Symfony/Bridge/Twig/Extension/FormExtension.php @@ -88,6 +88,7 @@ public function getFilters() { return array( new TwigFilter('humanize', array($this, 'humanize')), + new TwigFilter('form_encode_currency', array($this, 'encodeCurrency'), array('is_safe' => array('html'), 'needs_environment' => true)), ); } @@ -166,6 +167,22 @@ public function isRootForm(FormView $formView) return null === $formView->parent; } + /** + * @internal + */ + public function encodeCurrency(Environment $environment, $text, $widget = '') + { + if ('UTF-8' === $charset = $environment->getCharset()) { + $text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8'); + } else { + $text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8'); + $text = iconv('UTF-8', $charset, $text); + $widget = iconv('UTF-8', $charset, $widget); + } + + return str_replace('{{ widget }}', $widget, $text); + } + /** * {@inheritdoc} */ diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig index c61f28a2d302f..215f0ce754531 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/bootstrap_3_layout.html.twig @@ -25,11 +25,11 @@ {% if prepend or append %}
{% if prepend %} - {{ money_pattern|replace({ '{{ widget }}':''}) }} + {{ money_pattern|form_encode_currency }} {% endif %} {{- block('form_widget_simple') -}} {% if append %} - {{ money_pattern|replace({ '{{ widget }}':''}) }} + {{ money_pattern|form_encode_currency }} {% endif %}
{% else %} diff --git a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig index 922b3ec7a7cee..9f1d95f2782f1 100644 --- a/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig +++ b/src/Symfony/Bridge/Twig/Resources/views/Form/form_div_layout.html.twig @@ -142,7 +142,7 @@ {%- endblock integer_widget -%} {%- block money_widget -%} - {{ money_pattern|replace({ '{{ widget }}': block('form_widget_simple') })|raw }} + {{ money_pattern|form_encode_currency(block('form_widget_simple')) }} {%- endblock money_widget -%} {%- block url_widget -%} diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php index 85ef2ceed53af..2a22f7d88e2b3 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionBootstrap3LayoutTest.php @@ -63,6 +63,31 @@ protected function tearDown() $this->extension = null; } + public function testMoneyWidgetInIso() + { + $environment = new Environment(new StubFilesystemLoader(array( + __DIR__.'/../../Resources/views/Form', + __DIR__.'/Fixtures/templates/form', + )), array('strict_variables' => true)); + $environment->addExtension(new TranslationExtension(new StubTranslator())); + $environment->addExtension($this->extension); + $environment->setCharset('ISO-8859-1'); + + $this->extension->initRuntime($environment); + + $view = $this->factory + ->createNamed('name', 'money') + ->createView() + ; + + $this->assertSame(<<<'HTML' +
+ +
+HTML + , trim($this->renderWidget($view))); + } + protected function renderForm(FormView $view, array $vars = array()) { return (string) $this->extension->renderer->renderBlock($view, 'form', $vars); diff --git a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php index e11daf1831349..cb81f7bbc70ee 100644 --- a/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php +++ b/src/Symfony/Bridge/Twig/Tests/Extension/FormExtensionDivLayoutTest.php @@ -162,6 +162,26 @@ public function testIsRootForm($expected, FormView $formView) $this->assertSame($expected, $this->extension->isRootForm($formView)); } + public function testMoneyWidgetInIso() + { + $environment = new Environment(new StubFilesystemLoader(array( + __DIR__.'/../../Resources/views/Form', + __DIR__.'/Fixtures/templates/form', + )), array('strict_variables' => true)); + $environment->addExtension(new TranslationExtension(new StubTranslator())); + $environment->addExtension($this->extension); + $environment->setCharset('ISO-8859-1'); + + $this->extension->initRuntime($environment); + + $view = $this->factory + ->createNamed('name', 'money') + ->createView() + ; + + $this->assertSame('€ ', $this->renderWidget($view)); + } + protected function renderForm(FormView $view, array $vars = array()) { return (string) $this->extension->renderer->renderBlock($view, 'form', $vars); diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/money_widget.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/money_widget.html.php index 644d284915371..25fe13f7e057c 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/money_widget.html.php +++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/money_widget.html.php @@ -1 +1 @@ -block($form, 'form_widget_simple'), $money_pattern) ?> +formEncodeCurrency($money_pattern, $view['form']->block($form, 'form_widget_simple')) ?> diff --git a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php index 909fd14bb7ad6..ba63cad397c3a 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php +++ b/src/Symfony/Bundle/FrameworkBundle/Templating/Helper/FormHelper.php @@ -260,4 +260,20 @@ public function humanize($text) { return $this->renderer->humanize($text); } + + /** + * @internal + */ + public function formEncodeCurrency($text, $widget = '') + { + if ('UTF-8' === $charset = $this->getCharset()) { + $text = htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8'); + } else { + $text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8'); + $text = iconv('UTF-8', $charset, $text); + $widget = iconv('UTF-8', $charset, $widget); + } + + return str_replace('{{ widget }}', $widget, $text); + } } diff --git a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php index c745818b1e72b..b1e8efaa6d90d 100644 --- a/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php +++ b/src/Symfony/Bundle/FrameworkBundle/Tests/Templating/Helper/FormHelperDivLayoutTest.php @@ -61,6 +61,18 @@ protected function tearDown() parent::tearDown(); } + public function testMoneyWidgetInIso() + { + $this->engine->setCharset('ISO-8859-1'); + + $view = $this->factory + ->createNamed('name', 'money') + ->createView() + ; + + $this->assertSame('€ ', $this->renderWidget($view)); + } + protected function renderForm(FormView $view, array $vars = array()) { return (string) $this->engine->get('form')->form($view, $vars); diff --git a/src/Symfony/Bundle/FrameworkBundle/composer.json b/src/Symfony/Bundle/FrameworkBundle/composer.json index ed611114fe2aa..b910cd9ed33e9 100644 --- a/src/Symfony/Bundle/FrameworkBundle/composer.json +++ b/src/Symfony/Bundle/FrameworkBundle/composer.json @@ -30,7 +30,7 @@ "symfony/security-core": "~2.6.13|~2.7.9|~2.8", "symfony/security-csrf": "~2.6", "symfony/stopwatch": "~2.3", - "symfony/templating": "~2.1", + "symfony/templating": "~2.7", "symfony/translation": "~2.7", "doctrine/annotations": "~1.0" }, diff --git a/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php b/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php index bfdf92d9466b6..7f55dc123aab1 100644 --- a/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php +++ b/src/Symfony/Component/Form/Extension/Core/Type/MoneyType.php @@ -83,7 +83,7 @@ public function getName() } /** - * Returns the pattern for this locale. + * Returns the pattern for this locale in UTF-8. * * The pattern contains the placeholder "{{ widget }}" where the HTML tag should * be inserted pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy