Magento – Magento 2 code validation Unescaped output detected warning

magento2validation

I've created a Magento2 Module, When I validate the PHP code, am getting the Unescaped output detected.

I got the following solutions from that blog /* @noEscape */ moreover, it's not fixing the problem.

I want to know how to fix this issue, and need some detailed technical explanation of the /* @noEscape */

Best Answer

You can solve using This

For HTML Attribute

<?= $block->escapeHtmlAttr($var) ?>

or

<?= $block->escapeHtmlAttr("Demo text") ?>

For URL

<?= $block->escapeUrl($block->getUrl('*/*/forgotpasswordpost')) ?> 

For used insted of echo

<?= $block->escapeHtml('Name') ?>

<?= $block->escapeHtml($var) ?>

<?= /* @noEscape */ $var ?>

Note: Some time code is required then we not change in code so use this line

//@codingStandardsIgnoreStart

Your code 

//@codingStandardsIgnoreEnd

This is perform coding standard ignore this line

I Hope This Hepls You.

Related Topic