-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Changes from all commits
0a94383
95218e1
2c692c3
f128bcf
3887e49
768d1e2
9495826
a9e9081
b078f7e
73d5602
ee50318
1182c69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure $widget is always in UTF-8? This looks strange to me, because that would mean this is also bugged. Is it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i think we can assume we get raw html in UTF from the form component. Here we include it in a new safe html value concerning the target charset, using In general we are consistent with regular escaped output (ie. also in target charset) from There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At least we treated this as UTF before also (result from |
||
} | ||
|
||
return str_replace('{{ widget }}', $widget, $text); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,11 +25,11 @@ | |
{% if prepend or append %} | ||
<div class="input-group"> | ||
{% if prepend %} | ||
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span> | ||
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
{% endif %} | ||
{{- block('form_widget_simple') -}} | ||
{% if append %} | ||
<span class="input-group-addon">{{ money_pattern|replace({ '{{ widget }}':''}) }}</span> | ||
<span class="input-group-addon">{{ money_pattern|form_encode_currency }}</span> | ||
{% endif %} | ||
</div> | ||
{% else %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
<?php echo str_replace('{{ widget }}', $view['form']->block($form, 'form_widget_simple'), $money_pattern) ?> | ||
<?php echo $view['form']->formEncodeCurrency($money_pattern, $view['form']->block($form, 'form_widget_simple')) ?> |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. perhaps a conditional test is better, let me know. |
||
"symfony/translation": "~2.7", | ||
"doctrine/annotations": "~1.0" | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
$currency instead of $text, and mandatory $widget