Commit 018bd7c5 authored by alexpott's avatar alexpott

Issue #2765609 by c31ck, gnuget, hgoto, Yogesh Pawar, weboide, alexpott:...

Issue #2765609 by c31ck, gnuget, hgoto, Yogesh Pawar, weboide, alexpott: #plain_text doesn't render empty-like values (e.g. 0 and "0")
parent 91c29aea
......@@ -380,7 +380,7 @@ protected function doRender(&$elements, $is_root_call = FALSE) {
}
// All render elements support #markup and #plain_text.
if (!empty($elements['#markup']) || !empty($elements['#plain_text'])) {
if (isset($elements['#markup']) || isset($elements['#plain_text'])) {
$elements = $this->ensureMarkupIsSafe($elements);
}
......@@ -744,11 +744,7 @@ protected function xssFilterAdminIfUnsafe($string) {
* @see \Drupal\Component\Utility\Xss::filterAdmin()
*/
protected function ensureMarkupIsSafe(array $elements) {
if (empty($elements['#markup']) && empty($elements['#plain_text'])) {
return $elements;
}
if (!empty($elements['#plain_text'])) {
if (isset($elements['#plain_text'])) {
$elements['#markup'] = Markup::create(Html::escape($elements['#plain_text']));
}
elseif (!($elements['#markup'] instanceof MarkupInterface)) {
......
......@@ -89,6 +89,26 @@ public function providerTestRenderBasic() {
['#markup' => 'foo'],
'foo',
];
// Basic #markup based renderable array with value '0'.
$data[] = [
['#markup' => '0'],
'0',
];
// Basic #markup based renderable array with value 0.
$data[] = [
['#markup' => 0],
'0',
];
// Basic #markup based renderable array with value ''.
$data[] = [
['#markup' => ''],
'',
];
// Basic #markup based renderable array with value NULL.
$data[] = [
['#markup' => NULL],
'',
];
// Basic #plain_text based renderable array.
$data[] = [
['#plain_text' => 'foo'],
......@@ -104,6 +124,26 @@ public function providerTestRenderBasic() {
['#plain_text' => Markup::create('<em>foo</em>')],
'&lt;em&gt;foo&lt;/em&gt;',
];
// #plain_text based renderable array with value '0'.
$data[] = [
['#plain_text' => '0'],
'0',
];
// #plain_text based renderable array with value 0.
$data[] = [
['#plain_text' => 0],
'0',
];
// #plain_text based renderable array with value ''.
$data[] = [
['#plain_text' => ''],
'',
];
// #plain_text based renderable array with value NULL.
$data[] = [
['#plain_text' => NULL],
'',
];
// Renderable child element.
$data[] = [
['child' => ['#markup' => 'bar']],
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment