Skip to content

Commit b0ccd4f

Browse files
correctly handle escaping
1 parent 4d3a05d commit b0ccd4f

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

app/code/Magento/Catalog/Block/Product/Image.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @method string getHeight()
1515
* @method string getLabel()
1616
* @method float getRatio()
17-
* @method string getCustomAttributes()
17+
* @method array getCustomAttributes()
1818
* @method string getClass()
1919
* @since 100.0.2
2020
*/

app/code/Magento/Catalog/Block/Product/ImageFactory.php

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -67,23 +67,6 @@ public function __construct(
6767
$this->imageParamsBuilder = $imageParamsBuilder;
6868
}
6969

70-
/**
71-
* Retrieve image custom attributes for HTML element
72-
*
73-
* @param array $attributes
74-
* @return string
75-
*/
76-
private function getStringCustomAttributes(array $attributes): string
77-
{
78-
$result = [];
79-
foreach ($attributes as $name => $value) {
80-
if ($name != 'class') {
81-
$result[] = $name . '="' . $value . '"';
82-
}
83-
}
84-
return !empty($result) ? implode(' ', $result) : '';
85-
}
86-
8770
/**
8871
* Retrieve image class for HTML element
8972
*
@@ -161,7 +144,7 @@ public function create(Product $product, string $imageId, array $attributes = nu
161144
}
162145

163146
$attributes = $attributes === null ? [] : $attributes;
164-
147+
165148
$data = [
166149
'data' => [
167150
'template' => 'Magento_Catalog::product/image_with_borders.phtml',
@@ -170,7 +153,7 @@ public function create(Product $product, string $imageId, array $attributes = nu
170153
'height' => $imageMiscParams['image_height'],
171154
'label' => $this->getLabel($product, $imageMiscParams['image_type']),
172155
'ratio' => $this->getRatio($imageMiscParams['image_width'], $imageMiscParams['image_height']),
173-
'custom_attributes' => $this->getStringCustomAttributes($attributes),
156+
'custom_attributes' => $attributes,
174157
'class' => $this->getClass($attributes),
175158
'product_id' => $product->getId()
176159
],

app/code/Magento/Catalog/view/frontend/templates/product/image.phtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@
77
<?php /** @var $block \Magento\Catalog\Block\Product\Image */ ?>
88

99
<img class="photo image <?= $block->escapeHtmlAttr($block->getClass()) ?>"
10-
<?= /* @escapeNotVerified */ $block->getCustomAttributes() ?>
10+
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
11+
<?php if ($name !== 'class'): ?>
12+
<?= $block->escapeHtmlAttr($name) ?>="<?= $block->escapeHtmlAttr($value) ?>"
13+
<?php endif; ?>
14+
<?php endforeach; ?>
1115
src="<?= $block->escapeUrl($block->getImageUrl()) ?>"
1216
width="<?= $block->escapeHtmlAttr($block->getWidth()) ?>"
1317
height="<?= $block->escapeHtmlAttr($block->getHeight()) ?>"

app/code/Magento/Catalog/view/frontend/templates/product/image_with_borders.phtml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
<span class="product-image-wrapper"
1212
style="padding-bottom: <?= ($block->getRatio() * 100) ?>%;">
1313
<img class="<?= $block->escapeHtmlAttr($block->getClass()) ?>"
14-
<?= /* @escapeNotVerified */ $block->getCustomAttributes() ?>
14+
<?php foreach ($block->getCustomAttributes() as $name => $value): ?>
15+
<?php if ($name !== 'class'): ?>
16+
<?= $block->escapeHtmlAttr($name) ?>="<?= $block->escapeHtmlAttr($value) ?>"
17+
<?php endif; ?>
18+
<?php endforeach; ?>
1519
src="<?= $block->escapeUrl($block->getImageUrl()) ?>"
1620
max-width="<?= $block->escapeHtmlAttr($block->getWidth()) ?>"
1721
max-height="<?= $block->escapeHtmlAttr($block->getHeight()) ?>"

0 commit comments

Comments
 (0)