Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Component/BodyComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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('"', '&quot;', $value);

$parts[] = "{$name}=\"{$value}\"";
}

Expand Down
20 changes: 20 additions & 0 deletions tests/Integration/Component/MjImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,24 @@ public function testSrcsetAndSizesAttributesArePassedThrough(): void
$this->extractAttribute($html, 'img', 'sizes'),
);
}

public function testQuoteInAttributeValueStaysInsideTheAttribute(): void
{
$mjml = '
<mjml>
<mj-body>
<mj-section>
<mj-column>
<mj-image src="https://example.com/logo.png" alt="The &quot;Acme&quot; logo" />
</mj-column>
</mj-section>
</mj-body>
</mjml>';

$html = $this->renderMjml($mjml);

self::assertStringContainsString('alt="The &quot;Acme&quot; logo"', $html);
self::assertSame('The "Acme" logo', $this->extractAttribute($html, 'img', 'alt'));
self::assertNull($this->extractAttribute($html, 'img', 'acme&quot;'));
}
}
Loading