Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion lib/Caxy/HtmlDiff/Table/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,18 @@ protected function buildTableDoms()
*/
protected function createDocumentWithHtml($text)
{
// As DOMDocument::loadHTML() does not support UTF-8 properly without specifying the encoding in the HTML,
// we convert all non-ASCII characters to numeric entities.
$convmap = [
0x80, // Leave ASCII range intact
0x10FFFF, // Convert the rest of the Unicode range
0,
0xFFFFFF,
];
Comment on lines +631 to +636
Copy link

Copilot AI Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The convmap array uses magic numbers without clear documentation. Consider defining named constants for these Unicode range boundaries (0x80 for ASCII_END, 0x10FFFF for UNICODE_MAX) to improve code readability and maintainability.

Copilot uses AI. Check for mistakes.

$text = mb_encode_numericentity($text, $convmap, 'UTF-8');

$dom = new \DOMDocument();
$dom->loadHTML(htmlspecialchars_decode(iconv('UTF-8', 'ISO-8859-1//IGNORE', htmlentities($text, ENT_COMPAT, 'UTF-8')), ENT_QUOTES));
$dom->loadHTML($text);

return $dom;
}
Expand Down