caxy / php-htmldiff

A library for comparing two HTML files/snippets and highlighting the differences using simple HTML. Includes support for comparing complex lists and tables
http://php-htmldiff.caxy.com
GNU General Public License v2.0
202 stars 51 forks source link

nested/unclosed tags on attribute differences #113

Open ESI-Lille-devops opened 1 year ago

ESI-Lille-devops commented 1 year ago

When comparing identical tags (tag and content), of which one has an attribute that the other doesn't, the produced output presents two opening tags, the identical content, and only one closing tag. Also, although I am not sure of what the expected behavior is, if both have the attribute, with different values, no difference is detected and the output is the old html. The following code

<?php

require_once 'vendor/autoload.php';

use Caxy\HtmlDiff\HtmlDiff;

function compare($old, $new) {
    echo (new HtmlDiff($new, $old))->build() . "\n";
}

compare(
    '<p title="A">content</p>',
    '<p>content</p>'
);
compare(
    '<p>content</p>',
    '<p class="A">content</p>'
);
compare(
    '<p title="A">content</p>',
    '<p title="B">content</p>'
);

outputs the following :

<p class="diffmod"><p title="A" class="diffmod">content</p>
<p class="diffmod A"><p class="diffmod">content</p>
<p title="A">content</p>