Skip to content

Commit

Permalink
Issue with LIBXML_HTML_NOIMPLIED and templates with multiple roots …
Browse files Browse the repository at this point in the history
…Yireo_Webp2#175
  • Loading branch information
jissereitsma committed Feb 19, 2025
1 parent 92d895e commit 9ec75ee
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions Test/Unit/Util/HtmlReplacerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ public function testReplaceWithTestImage(string $originalHtml, string $expectedH
public function getTestReplaceWithTestImageArguments(): array
{
return [
[
'foobar',
'foobar',
],
[
'<p>foobar</p><p>foobar</p>',
'<p>foobar</p><p>foobar</p>',
],
[
'<div><img src="/img/test.png"/></div>',
'<div><img src="/img/test.png"/></div>'
Expand Down
9 changes: 9 additions & 0 deletions Util/HtmlReplacer.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ public function replace(string $html): string
*/
private function replaceImageTags(string $html): string
{
if (empty($html)) {
return $html;
}

$html = '<yireo_nextgenimages>'.$html.'</yireo_nextgenimages>';

$document = $this->domUtils->htmlToDOMDocument($html);
$images = $document->getElementsByTagName('img');
foreach ($images as $image) {
Expand All @@ -98,6 +104,9 @@ private function replaceImageTags(string $html): string
}
}

$html = str_replace('<yireo_nextgenimages>', '', $html);
$html = str_replace('</yireo_nextgenimages>', '', $html);

return $html;
}

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit 9ec75ee

Please sign in to comment.