Magento2: Product Details Page breadcrumbs cause syntax error on products containing quotes

Created on 7 May 2018  路  13Comments  路  Source: magento/magento2


Preconditions


  1. Magento version: 2.2.4

Steps to reproduce

  1. Add a product with " in the title, e.g. My Product - 19" x 16" Header
  2. Navigate to Product Details Page
  3. Observe the Syntax Error in the browser console

Expected result

  1. Template file should escape " in product name

Actual result

  1. Syntax Error occurs in console upon JSON Parse SyntaxError: Unexpected token x in JSON
dmcdindia Fixed in 2.2.x Fixed in 2.3.x Format is valid

Most helpful comment

I have the same issue here (also 2.2.4). I'll quick fix it for now (thanks @brian-labelle), but this definitely needs to be fixed.

All 13 comments

Magento_Catalog view/frontend/templates/product/breadcrumbs.phtml:

<div class="breadcrumbs" data-mage-init='{
    "breadcrumbs": {
        "categoryUrlSuffix": "<?= $block->escapeHtml($viewModel->getCategoryUrlSuffix()); ?>",
        "useCategoryPathInUrl": <?= (int)$viewModel->isCategoryUsedInProductUrl(); ?>,
        "product": "<?= $block->escapeHtml($viewModel->getProductName()); ?>"
    }
}'>
</div>

To fix the issue, the product name value must go through $block->escapeJs()

I have the same issue here (also 2.2.4). I'll quick fix it for now (thanks @brian-labelle), but this definitely needs to be fixed.

We have the same issue, is there any fix for this already?

@Bobstar040 : my best guess would be to implement the fix as described by @brian-labelle at the moment. I hope that this will be fixed in M2.2.5+ / M2.3, but probably @magento-engcom-team could shed more light on this.

Same issue here too with hundreds of products that contain quotes. I'll implement @brian-labelle 's fix.
Nice detailed fix: https://magento.stackexchange.com/q/224587/52084

@magento-engcom-team unable to re-produce the issue in 2.2-develop branch, magento version 2.2.6-dev.
breadcrumb #dmcdindia

I am working on this at #dmcdindia

Hi @brian-labelle. Thank you for your report.
The issue has been fixed in magento/magento2#15347 by @jignesh-baldha in 2.2-develop branch
Related commit(s):

The fix will be available with the upcoming 2.2.5 release.

Hi @brian-labelle. Thank you for your report.
The issue has been fixed in magento/magento2#16148 by @jignesh-baldha in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

Since @magento-engcom-team have not implemented this in 2.5.5... For anyone else who needs it, to implement the fix described by @brian-labelle in a theme.
cp app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml app/design/frontend/<vendor>/<theme>/Magento_Catalog/templates/product/
then edit
"product": "<?= $block->escapeHtml($viewModel->getProductName()); ?>"
to
"product": "<?= $block->escapeJs($viewModel->getProductName()); ?>"
then clear your cache.

You have to overwrite the file app/design/frontend/Vendor/Theme/Magento_Catalog/templates/product/breadcrumbs.phtml
then edit
"product": "escapeHtml($viewModel->getProductName()); ?>"
to
"product": "product": "escapeHtml($block->escapeJsQuote($viewModel->getProductName(), '"')); ?>"
then clear your cache.

Was this page helpful?
0 / 5 - 0 ratings