Skip to content

Conversation

Copy link

Copilot AI commented Dec 27, 2025

DOMDocument::loadHTML() emits warnings when parsing HTML fragments with malformed or mismatched tags, particularly in nested list structures with specific whitespace patterns.

Changes

Wrapped all loadHTML() calls with libxml_use_internal_errors() to suppress warnings while preserving previous error handling state:

  • ListDiffLines.php: listByLines() and setInnerHtml() methods
  • TableDiff.php: createDocumentWithHtml() method
$previousState = libxml_use_internal_errors(true);
$dom->loadHTML($html);
libxml_clear_errors();
libxml_use_internal_errors($previousState);

Added test fixture nested-list-warning.html reproducing the reported scenario.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/doctrine/cache/zipball/56cd022adb5514472cb144c087393c1821911d09
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/mZcNB6 /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/BpaZo0 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/ezyang/htmlpurifier/zipball/b287d2a16aceffbf6e0295559b39662612b77fcf
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/BpaZo0 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-enumerator/zipball/5c9eeac41b290a3712d88851518825ad78f45c71
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/mZcNB6 /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/BpaZo0 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/object-reflector/zipball/b4f479ebdbf63ac605d183ece17d8d7fe49c15c7
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/mZcNB6 /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/BpaZo0 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/recursion-context/zipball/539c6691e0623af6dc6f9c20384c120f963465a0
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/BpaZo0 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/resource-operations/zipball/05d5692a7993ecccd56a03e40cd7e5b09b1d404e
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/mZcNB6 /usr/bin/composer install (http block)
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/BpaZo0 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/type/zipball/75e2c2a32f5e0b3aef905b9ed0b179b953b3d7c7
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/BpaZo0 /usr/bin/composer install --no-interaction (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c
    • Triggering command: /usr/bin/php8.3 /usr/bin/php8.3 -n -c /tmp/BpaZo0 /usr/bin/composer install --no-interaction (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Warning: DOMDocument::loadHTML(): Unexpected end tag : u in Entity</issue_title>
<issue_description>We sometimes get this "Unexpected end tag" problem, and this is how to reproduce it. The following PHP file is very sensitive to spaces, so make sure each and every space is copied correct.y The above warning seems to go away when we use the "keep new lines" config option and remove all the spaces.

<html>

<p>This code fails.  To get it working, remove one space before the "ol" tag on line 31, which is just under "...Something here..." in $newHtml</p>

<?php

$oldHtml = '<ol>
        <li><u>Publication:</u>
          <ol>
            <li>This sentence.</li>
          </ol>
        </li>
        <li><u>Something here</u>:
          <ol>
            <li>Another item</li>
          </ol>
        </li>
      </ol>
      <ol>
        <li><u>Mars</u>:</li>
        <li>Saturn</li>
      </ol>';

      $newHtml = '<ol>
    <li><u>Publication:</u>
     <ol>
     <li>This sentence.</li>
     </ol>
     </li>
     <li><u>Something here</u>:
      <ol>
      <li>Another item</li>
      </ol>
      </li>
      <li><u>Mars</u>:
      <ol>
      <li>Saturn</li>
      </ol>
      </li>
    </ol>';

error_reporting(E_ALL);
ini_set('display_errors', '1');

require __DIR__ . '/../vendor/autoload.php';

use Caxy\HtmlDiff\HtmlDiff;
use Caxy\HtmlDiff\HtmlDiffConfig;

$config = new HtmlDiffConfig();
$config->setKeepNewLines(true);

$htmlDiff = HtmlDiff::create($oldHtml, $newHtml, $config);
$content = $htmlDiff->build();

echo "Diff is " . $content;

?>

</html>
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
<comment_new><author>@jschroed91</author><body>
@MykhailoSukovitsyn If you get a PR open for this, we will review and merge</body></comment_new>
</comments>

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@coderabbitai
Copy link

coderabbitai bot commented Dec 27, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 2 commits December 27, 2025 19:33
Co-authored-by: jschroed91 <2540804+jschroed91@users.noreply.github.com>
Co-authored-by: jschroed91 <2540804+jschroed91@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix warning for unexpected end tag in DOMDocument Suppress libxml errors in DOMDocument::loadHTML() calls Dec 27, 2025
Copilot AI requested a review from jschroed91 December 27, 2025 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Warning: DOMDocument::loadHTML(): Unexpected end tag : u in Entity

2 participants