Skip to content

Commit

Permalink
Poll: reintroduce output encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
schmitz-ilias committed Oct 23, 2024
1 parent e60b429 commit d62b678
Showing 1 changed file with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected function renderStackedChart(
$tooltips = [];
$color_index = 0;
foreach ($results->getOrderedAnswerIds() as $id) {
$label = nl2br($results->getAnswerText($id));
$label = $this->htmlSpecialCharsAsEntities($results->getAnswerText($id));
$total_votes = $results->getAnswerTotal($id);
$tooltip = $total_votes . ' (' . round($results->getAnswerPercentage($id)) . '%)';
$bar_config = new BarConfig();
Expand Down Expand Up @@ -135,15 +135,11 @@ protected function renderBarChart(
$dataset = $this->data_factory->dataset([$votes_label => $c_dimension]);

foreach ($results->getOrderedAnswerIds() as $id) {
$label = $this->htmlSpecialCharsAsEntities($results->getAnswerText($id));
$total_votes = $results->getAnswerTotal($id);
$tooltip = $total_votes . ' (' . round($results->getAnswerPercentage($id)) . '%)';
$dataset = $dataset->withPoint(
nl2br($results->getAnswerText($id)),
[$votes_label => $total_votes]
)->withAlternativeInformation(
nl2br($results->getAnswerText($id)),
[$votes_label => $tooltip]
);
$dataset = $dataset->withPoint($label, [$votes_label => $total_votes])
->withAlternativeInformation($label, [$votes_label => $tooltip]);
}

$bar_config = new BarConfig();
Expand All @@ -155,4 +151,9 @@ protected function renderBarChart(
->withBarConfigs([$votes_label => $bar_config]);
$tpl->setVariable('CHART', $this->ui_renderer->render($chart));
}

protected function htmlSpecialCharsAsEntities(string $string): string
{
return $this->refinery->encode()->htmlSpecialCharsAsEntities()->transform(nl2br($string));
}
}

0 comments on commit d62b678

Please sign in to comment.