diff --git a/.php_cs.dist b/.php_cs.dist
index 2d410bb..d7b95fb 100644
--- a/.php_cs.dist
+++ b/.php_cs.dist
@@ -23,7 +23,7 @@ return PhpCsFixer\Config::create()
],
'linebreak_after_opening_tag' => true,
'declare_strict_types' => true,
- 'mb_str_functions' => true,
+ 'mb_str_functions' => false,
'no_php4_constructor' => true,
'no_superfluous_phpdoc_tags' => false,
'no_unreachable_default_argument_value' => true,
diff --git a/src/ImageExtension.php b/src/ImageExtension.php
index 07f20cd..0d1ddfd 100644
--- a/src/ImageExtension.php
+++ b/src/ImageExtension.php
@@ -244,12 +244,16 @@ private function createImage(
foreach ($additionalTypes as $extension => $type) {
$srcset = null;
- if (isset($attributes['src'])) {
+ if (isset($attributes['src']) && (!isset($attributes['srcset']) || false === strpos($attributes['srcset'], $attributes['src'] . ' '))) {
$srcset = $this->addExtension($attributes['src'], $extension);
}
if (isset($attributes['srcset'])) {
- $srcset .= ', ' . $this->addExtension($attributes['srcset'], $extension);
+ if ($srcset) {
+ $srcset .= ', ';
+ }
+
+ $srcset .= $this->addExtension($attributes['srcset'], $extension);
}
if ($srcset) {
diff --git a/tests/Unit/ImageExtensionTest.php b/tests/Unit/ImageExtensionTest.php
index cfba564..892ddff 100644
--- a/tests/Unit/ImageExtensionTest.php
+++ b/tests/Unit/ImageExtensionTest.php
@@ -162,6 +162,64 @@ public function testPictureTag(): void
);
}
+ public function testComplexWebpPictureTag(): void
+ {
+ $imageExtension = new ImageExtension(null, [], ['webp' => 'image/webp']);
+
+ $this->assertSame(
+ '',
+ $imageExtension->getImage(
+ $this->image,
+ [
+ 'src' => 'sulu-400x400',
+ 'srcset' => 'sulu-100x100 460w, sulu-170x170 800w, sulu-400x400 1024w',
+ 'sizes' => '(max-width: 1024px) 100vw, (max-width: 800px) 100vw, 100vw',
+ 'id' => 'image-id',
+ 'class' => 'image-class',
+ 'alt' => 'Logo',
+ ]
+ )
+ );
+ }
+
+ public function testComplexWebpPictureTagRetina(): void
+ {
+ $imageExtension = new ImageExtension(null, [], ['webp' => 'image/webp']);
+
+ $this->assertSame(
+ '',
+ $imageExtension->getImage(
+ $this->image,
+ [
+ 'src' => 'sulu-100x100',
+ 'srcset' => 'sulu-100x100 1x, sulu-400x400 2x',
+ 'id' => 'image-id',
+ 'class' => 'image-class',
+ 'alt' => 'Logo',
+ ]
+ )
+ );
+ }
+
public function testPictureTagMinimalImage(): void
{
$imageExtension = new ImageExtension('/lazy');