Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[TwigBridge] Fix rendering of currency by MoneyType #26663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
revise
  • Loading branch information
ro0NL committed Mar 28, 2018
commit 768d1e2940d720eacb73dd2ac093e0c4a408b1b4
27 changes: 15 additions & 12 deletions 27 src/Symfony/Bridge/Twig/Extension/FormExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function getFilters()
{
return array(
new TwigFilter('humanize', array($this, 'humanize')),
new TwigFilter('form_html_entities', array($this, 'htmlEntities'), array('is_safe' => array('html'), 'needs_environment' => true)),
new TwigFilter('form_encode_currency', array($this, 'encodeCurrency'), array('is_safe' => array('html'), 'needs_environment' => true)),
);
}

Expand Down Expand Up @@ -127,17 +127,6 @@ public function humanize($text)
return $this->renderer->humanize($text);
}

public function htmlEntities(Environment $environment, $text)
{
$text = htmlentities($text, ENT_QUOTES | (defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');

if ('UTF-8' === $charset = $environment->getCharset()) {
return $text;
}

return iconv('UTF-8', $charset, $text);
}

/**
* Returns whether a choice is selected for a given form value.
*
Expand Down Expand Up @@ -178,6 +167,20 @@ public function isRootForm(FormView $formView)
return null === $formView->parent;
}

/**
* @internal
*/
public function encodeCurrency(Environment $environment, $text)
{
if ('UTF-8' === $charset = $environment->getCharset()) {
return htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
}

$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');

return iconv('UTF-8', $charset, $text);
}

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
{% if prepend or append %}
<div class="input-group">
{% if prepend %}
<span class="input-group-addon">{{ money_pattern|form_html_entities|replace({ '{{ widget }}':''})|raw }}</span>
<span class="input-group-addon">{{ money_pattern|form_encode_currency|replace({ '{{ widget }}':''})|raw }}</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the replacement should be done first, which will avoid the need for the |raw filter.

{% endif %}
{{- block('form_widget_simple') -}}
{% if append %}
<span class="input-group-addon">{{ money_pattern|form_html_entities|replace({ '{{ widget }}':''})|raw }}</span>
<span class="input-group-addon">{{ money_pattern|form_encode_currency|replace({ '{{ widget }}':''})|raw }}</span>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

{% endif %}
</div>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@
{%- endblock integer_widget -%}

{%- block money_widget -%}
{{ money_pattern|form_html_entities|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
{{ money_pattern|form_encode_currency|replace({ '{{ widget }}': block('form_widget_simple') })|raw }}
{%- endblock money_widget -%}

{%- block url_widget -%}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $view['form']->htmlEntities($money_pattern)) ?>
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $view['form']->formEncodeCurrency($money_pattern)) ?>
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,17 @@ public function humanize($text)
return $this->renderer->humanize($text);
}

public function htmlEntities($text)
/**
* @internal
*/
public function formEncodeCurrency($text)
{
$text = htmlentities($text, ENT_QUOTES | (defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');

if ('UTF-8' === $charset = $this->getCharset()) {
return $text;
return htmlspecialchars($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');
}

$text = htmlentities($text, ENT_QUOTES | (\defined('ENT_SUBSTITUTE') ? ENT_SUBSTITUTE : 0), 'UTF-8');

return iconv('UTF-8', $charset, $text);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.