Skip to content

Commit

Permalink
b_convert_encoding(): Handling HTML entities via mbstring is deprecat…
Browse files Browse the repository at this point in the history
…ed; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead
  • Loading branch information
escopecz committed Dec 21, 2023
1 parent f54e165 commit 9b68e0b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ public function decodeTokens(PageDisplayEvent $event): void

// replace slots
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10ffff, 0, 0xfffff], 'UTF-8'), LIBXML_NOERROR);
$xpath = new \DOMXPath($dom);

$divContent = $xpath->query('//*[@data-slot="dwc"]');
Expand All @@ -169,7 +169,7 @@ public function decodeTokens(PageDisplayEvent $event): void
}

$newnode = $dom->createDocumentFragment();
$newnode->appendXML('<![CDATA['.mb_convert_encoding($slotContent, 'HTML-ENTITIES', 'UTF-8').']]>');
$newnode->appendXML('<![CDATA['.mb_encode_numericentity($slotContent, [0x80, 0x10ffff, 0, 0xfffff], 'UTF-8').']]>');
$slot->parentNode->replaceChild($newnode, $slot);
}

Expand Down
4 changes: 2 additions & 2 deletions app/bundles/FormBundle/Model/FormModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,9 +874,9 @@ public function getFormList($limit = 10, \DateTime $dateFrom = null, \DateTime $
private function loadHTML(&$dom, $html): void
{
if (defined('LIBXML_HTML_NOIMPLIED') && defined('LIBXML_HTML_NODEFDTD')) {
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
$dom->loadHTML(mb_encode_numericentity($html, [0x80, 0x10ffff, 0, 0xfffff], 'UTF-8'), LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
} else {
$dom->loadHTML(mb_convert_encoding($html, 'HTML-ENTITIES', 'UTF-8'));
$dom->loadHTML(mb_encode_numericentity($html, [0x80, 0x10ffff, 0, 0xfffff], 'UTF-8'));
}
}

Expand Down
4 changes: 2 additions & 2 deletions app/bundles/PageBundle/EventListener/BuilderSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public function onPageDisplay(Events\PageDisplayEvent $event): void
// replace slots
if (count($params)) {
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10ffff, 0, 0xfffff], 'UTF-8'), LIBXML_NOERROR);
$xpath = new \DOMXPath($dom);

$divContent = $xpath->query('//*[@data-slot="segmentlist"]');
Expand Down Expand Up @@ -420,7 +420,7 @@ public function onPageDisplay(Events\PageDisplayEvent $event): void
// add form before first block of prefs center
if (isset($params['startform']) && str_contains($content, 'data-prefs-center')) {
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10ffff, 0, 0xfffff], 'UTF-8'), LIBXML_NOERROR);
$xpath = new \DOMXPath($dom);
// If use slots
$divContent = $xpath->query('//*[@data-prefs-center="1"]');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testEmailReportWithAggregatedColumnsAndTotals(): void
$result = [];
$content = $response->getContent();
$dom = new \DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'), LIBXML_NOERROR);
$dom->loadHTML(mb_encode_numericentity($content, [0x80, 0x10ffff, 0, 0xfffff], 'UTF-8'), LIBXML_NOERROR);
$tbody = $dom->getElementById('reportTable')->getElementsByTagName('tbody')[0];
$rows = $tbody->getElementsByTagName('tr');

Expand Down

0 comments on commit 9b68e0b

Please sign in to comment.