-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[Form][TwigBridge] Handle MoneyType with non UTF-8 charset #25167
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
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 |
---|---|---|
|
@@ -43,7 +43,7 @@ public function buildForm(FormBuilderInterface $builder, array $options) | |
*/ | ||
public function buildView(FormView $view, FormInterface $form, array $options) | ||
{ | ||
$view->vars['money_pattern'] = self::getPattern($options['currency']); | ||
$view->vars['money_pattern'] = htmlentities(self::getPattern($options['currency']), 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. this should be removed, buildView does not output html, that's not the correct layer |
||
} | ||
|
||
/** | ||
|
@@ -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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ protected function assertMatchesXpath($html, $expression, $count = 1) | |
try { | ||
// Wrap in <root> node so we can load HTML with multiple tags at | ||
// the top level | ||
$dom->loadXML('<root>'.$html.'</root>'); | ||
$dom->loadHTML('<!DOCTYPE html><html><body>'.$html.'</body></html>'); | ||
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. using |
||
} catch (\Exception $e) { | ||
$this->fail(sprintf( | ||
"Failed loading HTML:\n\n%s\n\nError: %s", | ||
|
@@ -71,17 +71,15 @@ protected function assertMatchesXpath($html, $expression, $count = 1) | |
)); | ||
} | ||
$xpath = new \DOMXPath($dom); | ||
$nodeList = $xpath->evaluate('/root'.$expression); | ||
$nodeList = $xpath->evaluate('/html/body'.$expression); | ||
|
||
if ($nodeList->length != $count) { | ||
$dom->formatOutput = true; | ||
$this->fail(sprintf( | ||
"Failed asserting that \n\n%s\n\nmatches exactly %s. Matches %s in \n\n%s", | ||
$expression, | ||
1 == $count ? 'once' : $count.' times', | ||
1 == $nodeList->length ? 'once' : $nodeList->length.' times', | ||
// strip away <root> and </root> | ||
substr($dom->saveHTML(), 6, -8) | ||
$html | ||
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. formatted output not worth the hassle IMHO. As saveHTML includes a doctype declaration either way. |
||
)); | ||
} else { | ||
$this->addToAssertionCount(1); | ||
|
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.
I really think this should be
|htmlentities
we should add the filter to FormExtension
Uh oh!
There was an error while loading. Please reload this page.
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.
Agree. Will patch soonish.
Also templates are UTF8 encoded by default right? Technically we shouldnt have to do any encoding conversion at all here. Instead the rendered template as a whole should be converted depending on the kernel charset i guess. Let's not go there for now.
Implicitly meaning the linked issue is (technically) not supported? Anyway.. htmlentities will settle :)
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.
That's not how Twig deals with charsets - so templates are ASCII that's the only thing we can tell from here.