From 9960e1f1d928633ab5a56f4f6f09578b91e6bebe Mon Sep 17 00:00:00 2001 From: berliner Date: Fri, 13 Dec 2024 02:03:58 +0100 Subject: [PATCH] HPC-9974: Fix footnotes logic so that characters that are not valid XML do not break text formatting --- .../ghi_content/modules/gho_footnotes/src/GhoFootnotes.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/html/modules/custom/ghi_content/modules/gho_footnotes/src/GhoFootnotes.php b/html/modules/custom/ghi_content/modules/gho_footnotes/src/GhoFootnotes.php index 2e6c498b7..765d1c3b6 100644 --- a/html/modules/custom/ghi_content/modules/gho_footnotes/src/GhoFootnotes.php +++ b/html/modules/custom/ghi_content/modules/gho_footnotes/src/GhoFootnotes.php @@ -33,6 +33,7 @@ public static function updateFootnotes($html, $build) { // Process the texts with footnotes. foreach (iterator_to_array($dom->getElementsByTagName('gho-footnotes-text')) as $node) { + /** @var \DOMNode $node */ $id = $node->getAttribute('data-id'); $node_inner_html = gho_footnotes_get_inner_html($node); $node_inner_html = preg_replace('/\s*/', '', $node_inner_html); @@ -74,6 +75,9 @@ public static function updateFootnotes($html, $build) { // Update the footnote references and remove the containing div. $node_inner_html = gho_footnotes_update_text($id, $node_inner_html, $references, $footnotes); + // We do some back and forth for special characters to prevent XML + // parsing errors. + $node_inner_html = htmlspecialchars_decode(htmlspecialchars($node_inner_html, ENT_DISALLOWED), ENT_XML1); $fragment = $dom->createDocumentFragment(); // Note that we add a newline here. This is made to prevent a strange // issue with the caption credits, that are sometimes appearing spaceless