Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
chris-pook opened this issue Oct 22, 2019 · 11 comments
Assignees
Labels
Component: Framework/Code Component: Framework/Image Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Severity: S2 Major restrictions or short-term circumventions are required until a fix is available.

Comments

@chris-pook
Copy link
Contributor

chris-pook commented Oct 22, 2019

(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

@m2-assistant
Copy link

m2-assistant bot commented Oct 22, 2019

Hi @chris-pook. Thank you for your report.
To help us process this issue please make sure that you provided the following information:

  • Summary of the issue
  • Information on your environment
  • Steps to reproduce
  • Expected and actual results

Please make sure that the issue is reproducible on the vanilla Magento instance following Steps to reproduce. To deploy vanilla Magento instance on our environment, please, add a comment to the issue:

@magento give me 2.3-develop instance - upcoming 2.3.x release

For more details, please, review the Magento Contributor Assistant documentation.

@chris-pook do you confirm that you were able to reproduce the issue on vanilla Magento instance following steps to reproduce?

  • yes
  • no

@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label Oct 22, 2019
@chris-pook chris-pook changed the title Custom attributes of images generated by Product\ImageBuilder don't render individually Custom attributes of images generated by Product\ImageBuilder don't render correctly Oct 22, 2019
@engcom-Charlie engcom-Charlie self-assigned this Oct 28, 2019
@m2-assistant
Copy link

m2-assistant bot commented Oct 28, 2019

Hi @engcom-Charlie. Thank you for working on this issue.
In order to make sure that issue has enough information and ready for development, please read and check the following instruction: 👇

  • 1. Verify that issue has all the required information. (Preconditions, Steps to reproduce, Expected result, Actual result).

    DetailsIf the issue has a valid description, the label Issue: Format is valid will be added to the issue automatically. Please, edit issue description if needed, until label Issue: Format is valid appears.

  • 2. Verify that issue has a meaningful description and provides enough information to reproduce the issue. If the report is valid, add Issue: Clear Description label to the issue by yourself.

  • 3. Add Component: XXXXX label(s) to the ticket, indicating the components it may be related to.

  • 4. Verify that the issue is reproducible on 2.3-develop branch

    Details- Add the comment @magento give me 2.3-develop instance to deploy test instance on Magento infrastructure.
    - If the issue is reproducible on 2.3-develop branch, please, add the label Reproduced on 2.3.x.
    - If the issue is not reproducible, add your comment that issue is not reproducible and close the issue and stop verification process here!

  • 5. Add label Issue: Confirmed once verification is complete.

  • 6. Make sure that automatic system confirms that report has been added to the backlog.

@engcom-Charlie
Copy link
Contributor

Hello @chris-pook
ImageBuilder class is deprecated(will be deleted at next release).
image

Please use ImageFactory for your actions.
image

So i have to close this issue.
Thanks for your report!

@chris-pook
Copy link
Contributor Author

Fair enough. Thanks.

@chris-pook chris-pook reopened this Oct 29, 2019
@ghost ghost unassigned engcom-Charlie Oct 29, 2019
@chris-pook
Copy link
Contributor Author

This still seems to be an issue with ImageFactory. The same template vendor/magento/module-catalog/view/frontend/templates/product/image_with_borders.phtml will render the image and this is where the escaping issue is happening.

@engcom-Charlie
Copy link
Contributor

@chris-pook could you update the description of issue and add new steps?

@engcom-Charlie
Copy link
Contributor

We are closing this issue due to inactivity. If you'd like to update it, please reopen the issue.

@chris-pook chris-pook changed the title Custom attributes of images generated by Product\ImageBuilder don't render correctly Custom attributes of images generated by Block\Product\ImageFactory don't render correctly Nov 13, 2019
@chris-pook
Copy link
Contributor Author

Updated description and description to reflect use of ImageFactory to replicate this issue.

@engcom-Charlie
Copy link
Contributor

@chris-pook Thank you for contribution and collaboration!
I can confirm this issue now.
image_2019_11_14T12_57_14_956Z

@engcom-Charlie engcom-Charlie added Component: Framework/Image Component: Framework/Code Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release labels Nov 14, 2019
@ghost ghost unassigned engcom-Charlie Nov 14, 2019
@magento-engcom-team magento-engcom-team added the Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development label Nov 14, 2019
@magento-engcom-team
Copy link
Contributor

✅ Confirmed by @engcom-Charlie
Thank you for verifying the issue. Based on the provided information internal tickets MC-23137 were created

Issue Available: @engcom-Charlie, You will be automatically unassigned. Contributors/Maintainers can claim this issue to continue. To reclaim and continue work, reassign the ticket to yourself.

@magento-engcom-team magento-engcom-team added the Fixed in 2.4.x The issue has been fixed in 2.4-develop branch label Mar 15, 2020
@ghost ghost removed Issue: Clear Description Gate 2 Passed. Manual verification of the issue description passed Issue: Confirmed Gate 3 Passed. Manual verification of the issue completed. Issue is confirmed Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Nov 3, 2020
@magento-engcom-team magento-engcom-team added Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Severity: S2 Major restrictions or short-term circumventions are required until a fix is available. labels Nov 3, 2020
@ghost ghost added this to Done in High Priority Backlog Nov 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Framework/Code Component: Framework/Image Fixed in 2.4.x The issue has been fixed in 2.4-develop branch Priority: P2 A defect with this priority could have functionality issues which are not to expectations. Progress: done Reproduced on 2.3.x The issue has been reproduced on latest 2.3 release Severity: S2 Major restrictions or short-term circumventions are required until a fix is available.
Projects
Development

No branches or pull requests

4 participants