From e44cea43d68fd4b4bb851e5b2e244783e4d2a47f Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Sat, 4 May 2019 16:50:30 -0700 Subject: [PATCH] ArrayHtml - Boundary cases for empty content. Code formatting. --- ext/afform/core/CRM/Afform/ArrayHtml.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/ext/afform/core/CRM/Afform/ArrayHtml.php b/ext/afform/core/CRM/Afform/ArrayHtml.php index b20c1e0fb0..e30682f6ce 100644 --- a/ext/afform/core/CRM/Afform/ArrayHtml.php +++ b/ext/afform/core/CRM/Afform/ArrayHtml.php @@ -17,6 +17,10 @@ class CRM_Afform_ArrayHtml { * Ex: '
Hello world
' */ public function convertArrayToHtml($array) { + if ($array === []) { + return ''; + } + $tag = empty($array['#tag']) ? self::DEFAULT_TAG : $array['#tag']; unset($array['#tag']); $children = empty($array['#children']) ? self::DEFAULT_TAG : $array['#children']; @@ -31,10 +35,12 @@ class CRM_Afform_ArrayHtml { throw new \RuntimeException("Malformed HTML attribute"); } if (is_string($attrValue)) { - $buf .= sprintf(' %s="%s"', $attrName, htmlentities($attrValue)); // FIXME attribute encoding + // FIXME attribute encoding + $buf .= sprintf(' %s="%s"', $attrName, htmlentities($attrValue)); } elseif (is_array($attrValue) && $this->allowStructuredAttribute($tag, $attrName)) { - $buf .= sprintf(' %s="%s"', $attrName, htmlentities(json_encode($attrValue))); // FIXME attribute encoding + // FIXME attribute encoding + $buf .= sprintf(' %s="%s"', $attrName, htmlentities(json_encode($attrValue))); } else { Civi::log()->warning('Afform: Cannot serialize attribute {attrName}', [ @@ -64,6 +70,10 @@ class CRM_Afform_ArrayHtml { * Ex: ['#tag' => 'div', 'class' => 'greeting', '#children' => ['Hello world']] */ public function convertHtmlToArray($html) { + if ($html === '') { + return []; + } + $doc = new DOMDocument(); $doc->loadHTML("$html"); -- 2.25.1