Problem/Motivation

After updating our system to PHP 8.2, we are facing this error:

Deprecated function: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in Caxy\HtmlDiff\Table\TableDiff->createDocumentWithHtml() (Zeile 630 in /var/www/html/docport/vendor/caxy/php-htmldiff/lib/Caxy/HtmlDiff/Table/TableDiff.php)

This not a bug of the diff module, but the Caxy library that is a requirement of a library required by the module.

Issue fork diff-3419173

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

dbielke1986 created an issue. See original summary.

himanshu_jhaloya made their first commit to this issue’s fork.

himanshu_jhaloya’s picture

Hi @dbielke1986 Is this a bug in the Caxy library related with.

himanshu_jhaloya’s picture

Status: Active » Needs review

To Fix the issue you can add the following code..
php-htmldiff/lib/Caxy/HtmlDiff/Table
/TableDiff.php

instead
line 592
$htmlDiff = HtmlDiff::create(
mb_convert_encoding($oldContent, 'UTF-8', 'HTML-ENTITIES'),
mb_convert_encoding($newContent, 'UTF-8', 'HTML-ENTITIES'),
$this->config
);
to
$htmlDiff = HtmlDiff::create(
htmlspecialchars_decode($oldContent, ENT_QUOTES | ENT_HTML5),
htmlspecialchars_decode($newContent, ENT_QUOTES | ENT_HTML5),
$this->config
);

instead
line 630---
$dom->loadHTML(mb_convert_encoding(
$this->purifyHtml(mb_convert_encoding($text, $this->config->getEncoding(), mb_detect_encoding($text))),
'HTML-ENTITIES',
$this->config->getEncoding()
));

to

$dom->loadHTML(mb_convert_encoding(
$this->purifyHtml(mb_convert_encoding($text, $this->config->getEncoding(), mb_detect_encoding($text))),
'HTML-ENTITIES',
$this->config->getEncoding()
));

dbielke1986’s picture

Status: Needs review » Needs work

I think we need an MR for this issue before it should be "Needs review".
Can you push your changes to an MR?

himanshu_jhaloya’s picture

Hi @dbielke1986 you please review if this works i will create the MR

bluegeek9’s picture

Category: Bug report » Task

The issue is with php-htmldiff. The library needs the patch, and then the dependency revision needs to increase.

https://github.com/caxy/php-htmldiff/issues/123

$dom->loadHTML(mb_convert_encoding(
    $this->purifyHtml(mb_convert_encoding($text, $this->config->getEncoding(), mb_detect_encoding($text))),
    'HTML-ENTITIES',
    $this->config->getEncoding()
));
$dom->loadHTML(htmlspecialchars_decode(iconv('UTF-8', 'ISO-8859-1', htmlentities($text, ENT_COMPAT, 'UTF-8')), ENT_QUOTES));
bluegeek9’s picture

Assigned: Unassigned » bluegeek9
Status: Needs work » Active
robpowell’s picture

anicoto’s picture

Issue summary: View changes

As the issue is in a module dependency and not the module itself, we need to wait until library maintainers approve the PR. For now, I apply the patch with composer using the vendor folder as this:

 "vendor/caxy/php-htmldiff": {
                "TableDiff: Deprecated function mb_convert_encoding() in PHP 8.2 - [#123]" : "https://patch-diff.githubusercontent.com/raw/caxy/php-htmldiff/pull/125.patch"
            }
bluegeek9’s picture

Assigned: bluegeek9 » Unassigned
jannakha’s picture

+1 for #10 comment

heddn’s picture

Status: Active » Postponed

This is postponed on an upstream fix.

biguzis’s picture

After patching as said in #10, I get error

iconv(): Detected an illegal character in input string in Caxy\HtmlDiff\Table\TableDiff->createDocumentWithHtml() (line 630 of /app/vendor/caxy/php-htmldiff/lib/Caxy/HtmlDiff/Table/TableDiff.php)

Adding //TRANSLIT solves issue for me.
Full line:

$dom->loadHTML(htmlspecialchars_decode(iconv('UTF-8', 'ISO-8859-1//TRANSLIT', htmlentities($text, ENT_COMPAT, 'UTF-8')), ENT_QUOTES));
acbramley’s picture

Status: Postponed » Closed (outdated)

https://github.com/caxy/php-htmldiff/releases/tag/v0.1.16 contains fixes for this and PHP 8.4 deprecations.

alistairmc’s picture

Can we get an update to the module to include the https://github.com/caxy/php-htmldiff/releases/tag/v0.1.16 version in the composer.json

acbramley’s picture

Diff doesn't directly depend on caxy/php-htmldiff, it's a dependency of mkalkbrenner/php-htmldiff-advanced.

ivnish’s picture

Thanks #14 //TRANSLIT helps me too.