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

Product Details Page breadcrumbs cause syntax error on products containing quotes #15037

Closed
brian-labelle opened this issue May 7, 2018 · 13 comments
Assignees
Labels
Event: dmcdindia Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed

Comments

@brian-labelle
Copy link
Contributor

brian-labelle commented May 7, 2018

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
@magento-engcom-team magento-engcom-team added the Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed label May 7, 2018
@brian-labelle
Copy link
Contributor Author

brian-labelle commented May 7, 2018

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()

@kanduvisla
Copy link
Contributor

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.

@Bobstar040
Copy link

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

@kanduvisla
Copy link
Contributor

@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.

@POLYPERFORMANCE
Copy link

POLYPERFORMANCE commented May 16, 2018

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

@chiragp-wagento
Copy link

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

@jignesh-baldha
Copy link
Member

I am working on this at #dmcdindia

@magento-engcom-team
Copy link
Contributor

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

The fix will be available with the upcoming 2.2.5 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label May 22, 2018
magento-team pushed a commit that referenced this issue May 22, 2018
 - Merge Pull Request #15347 from jignesh-baldha/magento2:jignesh-baldha-patch1
 - Merged commits:
   1. 6fcfb88
   2. bfb39b5
   3. 8e93b0d
@magento-engcom-team
Copy link
Contributor

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

The fix will be available with the upcoming 2.3.0 release.

@magento-engcom-team magento-engcom-team added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Jun 26, 2018
@dyron
Copy link

dyron commented Jul 17, 2018

Again not in Magento 2.2.5:
https://github.com/magento/magento2/blob/2.2.5/app/code/Magento/Catalog/view/frontend/templates/product/breadcrumbs.phtml#L14

@benhtn
Copy link

benhtn commented Sep 13, 2018

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.

@divyabhagat
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Event: dmcdindia Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed
Projects
None yet
Development

No branches or pull requests