yireo / Yireo_NextGenImages

44 stars 26 forks source link

Deprecated Functionality with PHP 8.2 #54

Closed Sharkozp closed 1 year ago

Sharkozp commented 1 year ago

Hi,

I am testing Magento 2.4.6-beta3 with PHP 8.2 and found deprecated functionality:

Deprecated Functionality: mb_convert_encoding(): Handling HTML entities via mbstring is deprecated; use htmlspecialchars, htmlentities, or mb_encode_numericentity/mb_decode_numericentity instead in /var/www/html/vendor/yireo/magento2-next-gen-images/Util/HtmlReplacer.php on line 183

Best wishes

hostep commented 1 year ago

Also running into this while testing Magento 2.4.6-beta8 on PHP 8.2

When I look into a similar piece of code inside Magento itself, I can see the following change between Magento 2.4.5-p1 and 2.4.6-beta8:

--- vendor/magento/module-page-builder/Model/Stage/HtmlFilter.php   2022-09-12 14:56:38.000000000 +0200
+++ vendor/magento/module-page-builder/Model/Stage/HtmlFilter.php   2023-02-13 02:30:40.000000000 +0100
@@ -41,11 +41,17 @@
     public function filterHtml(string $content): string
     {
         $dom = new \DOMDocument('1.0', 'UTF-8');
+        $previous = '';
         try {
             //this code is required because of https://bugs.php.net/bug.php?id=60021
             $previous = libxml_use_internal_errors(true);
             $content = '<div>' . $content . '</div>';
-            $string = mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8');
+            $convmap = [0x80, 0x10FFFF, 0, 0x1FFFFF];
+            $string = mb_encode_numericentity(
+                $content,
+                $convmap,
+                'UTF-8'
+            );
             $dom->loadHTML($string, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
         } catch (\Exception $e) {
             $this->loggerInterface->critical($e->getMessage());

If I try to apply the same kind of changes to the Yireo NextGenImages module, it no longer crashes.

@jissereitsma: would you be okay with a change like this in your module? I could send in a PR for this if you want.

jissereitsma commented 1 year ago

For reference https://php.watch/versions/8.2/mbstring-qprint-base64-uuencode-html-entities-deprecated

@hostep Yeah, I think this already is a great fix. I'll merge the fix and will release a new version right away. Thanks!

hostep commented 1 year ago

Thank you!

This issue can be closed now that this got fixed in version 0.3.13 I think.

jissereitsma commented 1 year ago

Thanks for the good work!