Skip to content

Custom attributes of images generated by Block\Product\ImageFactory don't render correctly #25219

Closed
@chris-pook

Description

@chris-pook
(i) This ticket is created automatically based on a verified GitHub issue.

{panel}
If you are starting to work on this Jira ticket, please notify issue reporter and authors of related community pull requests (if any) that you are going to work on this issue:

  1. Assign #25219 issue to yourself on Magento GitHub
  2. Add comment "Internal Magento team is working on this issue right now."
    {panel}
    When using the core product image factory it is no longer possible to add your own custom attributes to the markup produced, due to incorrect escaping of the html output.

######Preconditions

  1. Install Magento 2.3.3 & 2.3-develop

######Steps to reproduce (*)

  1. Within a block or viewModel use the \Magento\Catalog\Block\Product\ImageFactory class to create a Magento\Catalog\Block\Product\Image. Set a custom attribute "data-sku" with the value of the product's sku and render the image in a frontend template:
$attributes = <
    'data-sku' => $product->getSku()
>;

$image = $this->imageFactory->create($product, $imageId, $attributes);

######Expected result
The image html should render with each of the custom attribute values returned by getCustomAttributes() escaped. In this example <img data-sku="<sku>" />.

######Actual result (*)
The image renders with the entire getCustomAttributes() string escaped meaning the html is invalid and the attribute is not available on the html element. In this example <img &#x20;data-sku&#x3d;&quot;<sku>&quot; />.

This stems from an over zealous use of escapeHtmlAttr() here: f40f24c#diff-eed94ca7983b385a07b8fb5ee2dbc20d

Metadata

Metadata

Labels

Component: Framework/CodeComponent: Framework/ImageFixed in 2.4.xThe issue has been fixed in 2.4-develop branchPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions