Skip to content

Commit

Permalink
Merge pull request #38 from bnf/srcset-double-encoding
Browse files Browse the repository at this point in the history
[BUGFIX] Avoid double encoding in srcset attribute
  • Loading branch information
achimfritz authored Jun 26, 2024
2 parents 695185a + 055e81f commit 22ec05e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Classes/ViewHelpers/ImageViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function render(): string
$sourceOutputs[] = $tag->render();

// Build additional source with type webp if attribute addWebp is set and previously build tag is not type of webp already.
$type = $tag->getAttribute('type');
$type = htmlspecialchars_decode($tag->getAttribute('type') ?? '');
if ($type !== 'image/webp' && $this->pictureConfiguration->webpShouldBeAdded()) {
$tag = $this->addWebpImage($sourceConfiguration, $imageSrc);
array_unshift($sourceOutputs, $tag->render());
Expand Down Expand Up @@ -358,7 +358,7 @@ protected function addRetina(array $processingInstructions, TagBuilder $tag, Fil
// Process additional retina images. Tag value can be gathered for source tags from srcset value as there it
// was to be set already because adding retina is not mandatory.
if ($tag->hasAttribute('srcset')) {
$tagValue = $tag->getAttribute('srcset');
$tagValue = htmlspecialchars_decode($tag->getAttribute('srcset') ?? '');
$tag->removeAttribute('srcset');
} else {
$tagValue = $imageUriRegular;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<html
xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
xmlns:i="http://typo3.org/ns/B13/Picture/ViewHelpers"
data-namespace-typo3-fluid="true"
>
<i:image src="1" width="150c" height="150c"
useRetina="1"
sources="{md: {width: '1680c', height: '1000c'}}" />
</html>
20 changes: 20 additions & 0 deletions Tests/Functional/ViewHelpers/ImageViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,26 @@ public function imageWithSources(): void
self::assertTrue(str_contains(trim($content), '<img src='));
}

/**
* @test
*/
public function imageWithSourcesAndRetina(): void
{
$this->importCSVDataSet(__DIR__ . '/Fixtures/storage_with_file.csv');
$template = __DIR__ . '/Fixtures/ImageWithSourcesAndRetina.html';
$view = GeneralUtility::makeInstance(StandaloneView::class);
$view->setTemplatePathAndFilename($template);
$content = $view->render();
$this->assertProcessedFileExists(150, 150);
$this->assertProcessedFileExists(300, 300);
$this->assertProcessedFileExists(1680, 1000);
$this->assertProcessedFileExists(3360, 2000);
self::assertTrue(str_starts_with(trim($content), '<picture><source srcset='));
self::assertTrue(str_contains(trim($content), '<img src='));
self::assertTrue(!str_contains(trim($content), 'eID=dumpFile&amp;amp;'));
self::assertTrue(str_contains(trim($content), 'eID=dumpFile&amp;t='));
}

/**
* @test
*/
Expand Down

0 comments on commit 22ec05e

Please sign in to comment.