diff --git a/Block/Picture.php b/Block/Picture.php index 521ff0d..334b169 100644 --- a/Block/Picture.php +++ b/Block/Picture.php @@ -249,6 +249,22 @@ public function getOriginalAttributesAsString(): string return implode(' ', $this->getOriginalAttributes()); } + public function getSourceAttributesAsString(): string + { + $allowedSourceAttributes = ['media', 'sizes']; + $sourceAttributes = []; + foreach ($this->getOriginalAttributes() as $originalAttribute) { + $originalAttributeArray = explode('=', $originalAttribute); + if (false === in_array($originalAttributeArray[0], $allowedSourceAttributes)) { + continue; + } + + $sourceAttributes[] = $originalAttribute; + } + + return implode(' ', $sourceAttributes); + } + /** * @return string[] */ diff --git a/CHANGELOG.md b/CHANGELOG.md index b49354a..12cb8f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Fixed +- Only re-use limited set of HTML attributes for source-tags #78 ## [0.5.3] - 22 May 2024 ### Fixed diff --git a/Test/Integration/Block/PictureTest.php b/Test/Integration/Block/PictureTest.php index 5d20d45..cec7e18 100644 --- a/Test/Integration/Block/PictureTest.php +++ b/Test/Integration/Block/PictureTest.php @@ -21,12 +21,18 @@ public function testPictureCreation() $images = [new Image('/tmp/pub/images/test.webp', '/images/test.webp')]; $pictureFactory = $this->objectManager->create(PictureFactory::class); - $picture = $pictureFactory->create($originalImage, $images, ''); + $picture = $pictureFactory->create($originalImage, $images, ''); $html = $picture->toHtml(); $this->assertNotEmpty($html); $this->assertStringContainsString('assertStringContainsString('', $html); + $this->assertStringContainsString('', $html); + + preg_match_all('#]+)>#msi', $html, $matches); + foreach ($matches[0] as $match) { + $this->assertStringNotContainsString('class="foobar"', $match); + $this->assertStringNotContainsString('fetchpriority="high"', $match); + } } /** diff --git a/Test/Integration/Util/HtmlReplacerTest.php b/Test/Integration/Util/HtmlReplacerTest.php index a0ed627..66b83aa 100644 --- a/Test/Integration/Util/HtmlReplacerTest.php +++ b/Test/Integration/Util/HtmlReplacerTest.php @@ -95,7 +95,7 @@ public function getTestReplaceWithTestImageArguments(): array ], [ '
', - '
' + '
' ], [ "", diff --git a/view/frontend/templates/picture.phtml b/view/frontend/templates/picture.phtml index ffa2aa8..fa1c088 100644 --- a/view/frontend/templates/picture.phtml +++ b/view/frontend/templates/picture.phtml @@ -30,7 +30,7 @@ $class ?>> getImages() as $image): ?> ="getUrl() ?>" - getOriginalAttributesAsString() ?> + getSourceAttributesAsString() ?> >