From 9ec75ee951f9077376014c3c017052dc395a4405 Mon Sep 17 00:00:00 2001 From: Jisse Reitsma Date: Wed, 19 Feb 2025 13:50:19 +0100 Subject: [PATCH] Issue with `LIBXML_HTML_NOIMPLIED` and templates with multiple roots Yireo_Webp2#175 --- CHANGELOG.md | 4 ++++ Test/Unit/Util/HtmlReplacerTest.php | 8 ++++++++ Util/HtmlReplacer.php | 9 +++++++++ composer.json | 2 +- 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb3af19..c8a0039 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.5.12] - 19 February 2025 +### Fixed +- Issue with `LIBXML_HTML_NOIMPLIED` and templates with multiple roots Yireo_Webp2#175 + ## [0.5.11] - 11 February 2025 ### Fixed - Fix possible warning with DOM loading diff --git a/Test/Unit/Util/HtmlReplacerTest.php b/Test/Unit/Util/HtmlReplacerTest.php index 08db102..ae06549 100644 --- a/Test/Unit/Util/HtmlReplacerTest.php +++ b/Test/Unit/Util/HtmlReplacerTest.php @@ -78,6 +78,14 @@ public function testReplaceWithTestImage(string $originalHtml, string $expectedH public function getTestReplaceWithTestImageArguments(): array { return [ + [ + 'foobar', + 'foobar', + ], + [ + '

foobar

foobar

', + '

foobar

foobar

', + ], [ '
', '
' diff --git a/Util/HtmlReplacer.php b/Util/HtmlReplacer.php index afa32da..2bec3ad 100644 --- a/Util/HtmlReplacer.php +++ b/Util/HtmlReplacer.php @@ -88,6 +88,12 @@ public function replace(string $html): string */ private function replaceImageTags(string $html): string { + if (empty($html)) { + return $html; + } + + $html = ''.$html.''; + $document = $this->domUtils->htmlToDOMDocument($html); $images = $document->getElementsByTagName('img'); foreach ($images as $image) { @@ -98,6 +104,9 @@ private function replaceImageTags(string $html): string } } + $html = str_replace('', '', $html); + $html = str_replace('', '', $html); + return $html; } diff --git a/composer.json b/composer.json index 044d3dd..4e954b9 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "yireo/magento2-next-gen-images", "license": "OSL-3.0", - "version": "0.5.11", + "version": "0.5.12", "type": "magento2-module", "homepage": "https://www.yireo.com/software/magento-extensions/next-gen-images", "description": "Magento 2 module to add NextGen images support to the Magento frontend",