diff --git a/src/Component/BodyComponent.php b/src/Component/BodyComponent.php index 2ceadcb..747225e 100644 --- a/src/Component/BodyComponent.php +++ b/src/Component/BodyComponent.php @@ -70,6 +70,10 @@ protected function htmlAttributes(array $attributes): string } } + // The XML parser decodes " to a bare quote, which would end the attribute early. + // Other characters stay as MJML writes them, so placeholders like <% x %> keep working. + $value = str_replace('"', '"', $value); + $parts[] = "{$name}=\"{$value}\""; } diff --git a/tests/Integration/Component/MjImageTest.php b/tests/Integration/Component/MjImageTest.php index 072f7ca..86443f7 100644 --- a/tests/Integration/Component/MjImageTest.php +++ b/tests/Integration/Component/MjImageTest.php @@ -96,4 +96,24 @@ public function testSrcsetAndSizesAttributesArePassedThrough(): void $this->extractAttribute($html, 'img', 'sizes'), ); } + + public function testQuoteInAttributeValueStaysInsideTheAttribute(): void + { + $mjml = ' + + + + + + + + + '; + + $html = $this->renderMjml($mjml); + + self::assertStringContainsString('alt="The "Acme" logo"', $html); + self::assertSame('The "Acme" logo', $this->extractAttribute($html, 'img', 'alt')); + self::assertNull($this->extractAttribute($html, 'img', 'acme"')); + } }