Skip to content
Draft
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ vendor/
/demo/bower_components
/demo/node_modules
.DS_Store
.idea
.idea
.phpunit.result.cache
14 changes: 14 additions & 0 deletions lib/Caxy/HtmlDiff/ListDiffLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,19 @@ protected function listByLines(string $old, string $new) : string
$new = mb_encode_numericentity($new, [0x80, 0x10FFFF, 0, ~0], 'UTF-8');
$old = mb_encode_numericentity($old, [0x80, 0x10FFFF, 0, ~0], 'UTF-8');

// Suppress libxml errors to avoid warnings from malformed HTML fragments
$previousLibxmlUseInternalErrors = libxml_use_internal_errors(true);

$newDom = new DOMDocument();
$newDom->loadHTML($new);

$oldDom = new DOMDocument();
$oldDom->loadHTML($old);

// Restore previous libxml error handling state
libxml_clear_errors();
libxml_use_internal_errors($previousLibxmlUseInternalErrors);

$newListNode = $this->findListNode($newDom);
$oldListNode = $this->findListNode($oldDom);

Expand Down Expand Up @@ -405,9 +412,16 @@ private function setInnerHtml(DOMNode $node, string $html) : void

$node->nodeValue = '';

// Suppress libxml errors to avoid warnings from malformed HTML fragments
$previousLibxmlUseInternalErrors = libxml_use_internal_errors(true);

$bufferDom = new DOMDocument('1.0', 'UTF-8');
$bufferDom->loadHTML($html);

// Restore previous libxml error handling state
libxml_clear_errors();
libxml_use_internal_errors($previousLibxmlUseInternalErrors);

$bodyNode = $bufferDom->getElementsByTagName('body')->item(0);

foreach ($bodyNode->childNodes as $childNode) {
Expand Down
7 changes: 7 additions & 0 deletions lib/Caxy/HtmlDiff/Table/TableDiff.php
Original file line number Diff line number Diff line change
Expand Up @@ -626,9 +626,16 @@ protected function buildTableDoms()
*/
protected function createDocumentWithHtml($text)
{
// Suppress libxml errors to avoid warnings from malformed HTML fragments
$previousLibxmlUseInternalErrors = libxml_use_internal_errors(true);

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

// Restore previous libxml error handling state
libxml_clear_errors();
libxml_use_internal_errors($previousLibxmlUseInternalErrors);

return $dom;
}

Expand Down
46 changes: 46 additions & 0 deletions tests/fixtures/HtmlDiff/nested-list-warning.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<options>
<option type="boolean" name="setKeepNewLines" value="true" />
</options>

<oldText><ol>
<li>
<ol>
<li>This sentence.</li>
</ol>
</li>
<li>:
<ol>
<li>Another item</li>
</ol>
</li>
</ol>
<ol>
<li>:</li>
<li>Saturn</li>
</ol></oldText>

<newText><ol>
<li>
<ol>
<li>This sentence.</li>
</ol>
</li>
<li>:
<ol>
<li>Another item</li>
</ol>
</li>
<li>:
<ol>
<li>Saturn</li>
</ol>
</li>
</ol></newText>

<expected><ol class="diff-list"><li class="normal new"><ins>
<ol>
<li>This sentence.</li>
</ol>
</ins></li><li class="normal"><ins class="diffins">:
</ins><ol class="diff-list"><li class="removed"><del>This sentence.</del></li><li class="replacement"><ins>Another item</ins></li></ol></li><li class="normal">:
<ol class="diff-list"><li class="removed"><del>Another item</del></li><li class="replacement"><ins>Saturn</ins></li></ol></li></ol><ol class="diffmod"><li class="diffmod"><del class="diffdel">:</del></li><li class="diffmod"><del class="diffdel">Saturn</del></li></ol></expected>