Skip to content

Magento_Catalog: avoid using deprecated escape* methods from Abstract… #31684

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

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function setExpandedPath($path)
protected function _getNodeJson($node, $level = 1)
{
$item = [];
$item['text'] = $this->escapeHtml($node->getName());
$item['text'] = $this->_escaper->escapeHtml($node->getName());
if ($this->_withProductCount) {
$item['text'] .= ' (' . $node->getProductCount() . ')';
}
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Adminhtml/Category/Tree.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ protected function _getNodeJson($node, $level = 0)
*/
public function buildNodeName($node)
{
$result = $this->escapeHtml($node->getName());
$result = $this->_escaper->escapeHtml($node->getName());
$result .= ' (ID: ' . $node->getId() . ')';
if ($this->_withProductCount) {
$result .= ' (' . $node->getProductCount() . ')';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function (node, e) {
}
';
} else {
$chooserJsObject = $this->escapeJs($this->getId());
$chooserJsObject = $this->_escaper->escapeJs($this->getId());
$js = '
function (node, e) {
' .
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ public function getHeaderText()
if (is_array($frontendLabel)) {
$frontendLabel = $frontendLabel[0];
}
return __('Edit Product Attribute "%1"', $this->escapeHtml($frontendLabel));
return __('Edit Product Attribute "%1"', $this->_escaper->escapeHtml($frontendLabel));
}
return __('New Product Attribute');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function _prepareLayout()
\Magento\Backend\Block\Widget\Button::class,
[
'label' => __('Delete'),
'onclick' => 'deleteConfirm(\'' . $this->escapeJs(
'onclick' => 'deleteConfirm(\'' . $this->_escaper->escapeJs(
__(
'You are about to delete all products in this attribute set. '
. 'Are you sure you want to do that?'
Expand Down Expand Up @@ -233,7 +233,7 @@ public function getGroupTreeJson()
/* @var $node \Magento\Eav\Model\Entity\Attribute\Group */
foreach ($groups as $node) {
$item = [];
$item['text'] = $this->escapeHtml($node->getAttributeGroupName());
$item['text'] = $this->_escaper->escapeHtml($node->getAttributeGroupName());
$item['id'] = $node->getAttributeGroupId();
$item['cls'] = 'folder';
$item['allowDrop'] = true;
Expand Down Expand Up @@ -280,7 +280,7 @@ public function getAttributeTreeJson()

foreach ($attributes as $child) {
$attr = [
'text' => $this->escapeHtml($child->getAttributeCode()),
'text' => $this->_escaper->escapeHtml($child->getAttributeCode()),
'id' => $child->getAttributeId(),
'cls' => 'leaf',
'allowDrop' => false,
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public function getDuplicateUrl()
public function getHeader()
{
if ($this->getProduct()->getId()) {
$header = $this->escapeHtml($this->getProduct()->getName());
$header = $this->_escaper->escapeHtml($this->getProduct()->getName());
} else {
$header = __('New Product');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function getSelectorOptions()
'showRecent' => true,
'storageKey' => 'product-template-key',
'minLength' => 0,
'currentlySelected' => $this->escapeHtml(
'currentlySelected' => $this->_escaper->escapeHtml(
$this->_coreRegistry->registry('product')->getAttributeSetId()
)
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ public function getChooseFromStoreHtml($storeTo)
if (!$this->hasWebsite($_website->getId())) {
continue;
}
$optGroupLabel = $this->escapeHtml($_website->getName());
$optGroupLabel = $this->_escaper->escapeHtml($_website->getName());
$this->_storeFromHtml .= '<optgroup label="' . $optGroupLabel . '"></optgroup>';
foreach ($this->getGroupCollection($_website) as $_group) {
$optGroupName = $this->escapeHtml($_group->getName());
$optGroupName = $this->_escaper->escapeHtml($_group->getName());
$this->_storeFromHtml .= '<optgroup label="&nbsp;&nbsp;&nbsp;&nbsp;' . $optGroupName . '">';
foreach ($this->getStoreCollection($_group) as $_store) {
$this->_storeFromHtml .= '<option value="' . $_store->getId() . '">&nbsp;&nbsp;&nbsp;&nbsp;';
$this->_storeFromHtml .= $this->escapeHtml($_store->getName()) . '</option>';
$this->_storeFromHtml .= $this->_escaper->escapeHtml($_store->getName()) . '</option>';
}
}
$this->_storeFromHtml .= '</optgroup>';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function (node, e) {
{jsObject}.categoryName = node.attributes.id != "none" ? node.text : false;
}
';
$js = str_replace('{jsObject}', $this->escapeJs($this->getJsObjectName()), $js);
$js = str_replace('{jsObject}', $this->_escaper->escapeJs($this->getJsObjectName()), $js);
return $js;
}

Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/Block/Product/Price.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public function getRealPriceJs($product)
*/
public function prepareSku($sku)
{
return $this->escapeHtml($this->string->splitInjection($sku));
return $this->_escaper->escapeHtml($this->string->splitInjection($sku));
}

/**
Expand Down
32 changes: 16 additions & 16 deletions app/code/Magento/Catalog/Block/Product/View/GalleryOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,49 +60,49 @@ public function getOptionsJson()
if (is_bool($this->getVar("gallery/nav"))) {
$optionItems['nav'] = $this->getVar("gallery/nav") ? 'true' : 'false';
} else {
$optionItems['nav'] = $this->escapeHtml($this->getVar("gallery/nav"));
$optionItems['nav'] = $this->_escaper->escapeHtml($this->getVar("gallery/nav"));
}

$optionItems['loop'] = $this->getVar("gallery/loop");
$optionItems['keyboard'] = $this->getVar("gallery/keyboard");
$optionItems['arrows'] = $this->getVar("gallery/arrows");
$optionItems['allowfullscreen'] = $this->getVar("gallery/allowfullscreen");
$optionItems['showCaption'] = $this->getVar("gallery/caption");
$optionItems['width'] = (int)$this->escapeHtml(
$optionItems['width'] = (int)$this->_escaper->escapeHtml(
$this->gallery->getImageAttribute('product_page_image_medium', 'width')
);
$optionItems['thumbwidth'] = (int)$this->escapeHtml(
$optionItems['thumbwidth'] = (int)$this->_escaper->escapeHtml(
$this->gallery->getImageAttribute('product_page_image_small', 'width')
);

if ($this->gallery->getImageAttribute('product_page_image_small', 'height') ||
$this->gallery->getImageAttribute('product_page_image_small', 'width')) {
$optionItems['thumbheight'] = (int)$this->escapeHtml(
$optionItems['thumbheight'] = (int)$this->_escaper->escapeHtml(
$this->gallery->getImageAttribute('product_page_image_small', 'height') ?:
$this->gallery->getImageAttribute('product_page_image_small', 'width')
);
}

if ($this->gallery->getImageAttribute('product_page_image_medium', 'height') ||
$this->gallery->getImageAttribute('product_page_image_medium', 'width')) {
$optionItems['height'] = (int)$this->escapeHtml(
$optionItems['height'] = (int)$this->_escaper->escapeHtml(
$this->gallery->getImageAttribute('product_page_image_medium', 'height') ?:
$this->gallery->getImageAttribute('product_page_image_medium', 'width')
);
}

if ($this->getVar("gallery/transition/duration")) {
$optionItems['transitionduration'] =
(int)$this->escapeHtml($this->getVar("gallery/transition/duration"));
(int)$this->_escaper->escapeHtml($this->getVar("gallery/transition/duration"));
}

$optionItems['transition'] = $this->escapeHtml($this->getVar("gallery/transition/effect"));
$optionItems['transition'] = $this->_escaper->escapeHtml($this->getVar("gallery/transition/effect"));
$optionItems['navarrows'] = $this->getVar("gallery/navarrows");
$optionItems['navtype'] = $this->escapeHtml($this->getVar("gallery/navtype"));
$optionItems['navdir'] = $this->escapeHtml($this->getVar("gallery/navdir"));
$optionItems['navtype'] = $this->_escaper->escapeHtml($this->getVar("gallery/navtype"));
$optionItems['navdir'] = $this->_escaper->escapeHtml($this->getVar("gallery/navdir"));

if ($this->getVar("gallery/thumbmargin")) {
$optionItems['thumbmargin'] = (int)$this->escapeHtml($this->getVar("gallery/thumbmargin"));
$optionItems['thumbmargin'] = (int)$this->_escaper->escapeHtml($this->getVar("gallery/thumbmargin"));
}

return $this->jsonSerializer->serialize($optionItems);
Expand All @@ -124,31 +124,31 @@ public function getFSOptionsJson()
if (is_bool($this->getVar("gallery/fullscreen/nav"))) {
$fsOptionItems['nav'] = $this->getVar("gallery/fullscreen/nav") ? 'true' : 'false';
} else {
$fsOptionItems['nav'] = $this->escapeHtml($this->getVar("gallery/fullscreen/nav"));
$fsOptionItems['nav'] = $this->_escaper->escapeHtml($this->getVar("gallery/fullscreen/nav"));
}

$fsOptionItems['loop'] = $this->getVar("gallery/fullscreen/loop");
$fsOptionItems['navdir'] = $this->escapeHtml($this->getVar("gallery/fullscreen/navdir"));
$fsOptionItems['navdir'] = $this->_escaper->escapeHtml($this->getVar("gallery/fullscreen/navdir"));
$fsOptionItems['navarrows'] = $this->getVar("gallery/fullscreen/navarrows");
$fsOptionItems['navtype'] = $this->escapeHtml($this->getVar("gallery/fullscreen/navtype"));
$fsOptionItems['navtype'] = $this->_escaper->escapeHtml($this->getVar("gallery/fullscreen/navtype"));
$fsOptionItems['arrows'] = $this->getVar("gallery/fullscreen/arrows");
$fsOptionItems['showCaption'] = $this->getVar("gallery/fullscreen/caption");

if ($this->getVar("gallery/fullscreen/transition/duration")) {
$fsOptionItems['transitionduration'] = (int)$this->escapeHtml(
$fsOptionItems['transitionduration'] = (int)$this->_escaper->escapeHtml(
$this->getVar("gallery/fullscreen/transition/duration")
);
}

$fsOptionItems['transition'] = $this->escapeHtml($this->getVar("gallery/fullscreen/transition/effect"));
$fsOptionItems['transition'] = $this->_escaper->escapeHtml($this->getVar("gallery/fullscreen/transition/effect"));

if ($this->getVar("gallery/fullscreen/keyboard")) {
$fsOptionItems['keyboard'] = $this->getVar("gallery/fullscreen/keyboard");
}

if ($this->getVar("gallery/fullscreen/thumbmargin")) {
$fsOptionItems['thumbmargin'] =
(int)$this->escapeHtml($this->getVar("gallery/fullscreen/thumbmargin"));
(int)$this->_escaper->escapeHtml($this->getVar("gallery/fullscreen/thumbmargin"));
}

return $this->jsonSerializer->serialize($fsOptionItems);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@
*/

/**
* @var $block \Magento\Catalog\Block\Adminhtml\Category\Tree
* @var \Magento\Catalog\Block\Adminhtml\Category\Tree $block
* @var \Magento\Framework\Escaper $escaper
*/
?>

<?php $divId = $block->escapeHtml('tree-div_' . time()) ?>
<?php $divId = $escaper->escapeHtml('tree-div_' . time()) ?>
<div id="<?= /* @noEscape */ $divId ?>" class="tree"></div>
<script id="ie-deferred-loader" defer="defer" src="//:"></script>

<script type="text/x-magento-init">
{
"*": {
"categoryCheckboxTree": {
"dataUrl": "<?= $block->escapeUrl($block->getLoadTreeUrl()) ?>",
"dataUrl": "<?= $escaper->escapeUrl($block->getLoadTreeUrl()) ?>",
"divId": "<?= /* @noEscape */ $divId ?>",
"rootVisible": false,
"useAjax": <?= $block->escapeHtml($block->getUseAjax()) ?>,
"useAjax": <?= $escaper->escapeHtml($block->getUseAjax()) ?>,
"currentNodeId": <?= (int)$block->getCategoryId() ?>,
"jsFormObject": "<?= /* @noEscape */ $block->getJsFormObject() ?>",
"name": "<?= $block->escapeHtml($block->getRoot()->getName()) ?>",
"checked": "<?= $block->escapeHtml($block->getRoot()->getChecked()) ?>",
"name": "<?= $escaper->escapeHtml($block->getRoot()->getName()) ?>",
"checked": "<?= $escaper->escapeHtml($block->getRoot()->getChecked()) ?>",
"allowdDrop": <?= /* @noEscape */ $block->getRoot()->getIsVisible() ? 'true' : 'false' ?>,
"rootId": <?= (int)$block->getRoot()->getId() ?>,
"expanded": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
*/

/**
* @var $block \Magento\Catalog\Block\Adminhtml\Category\Edit
* @var \Magento\Catalog\Block\Adminhtml\Category\Edit $block
* @var \Magento\Framework\Escaper $escaper
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
*/
?>
<div data-id="information-dialog-category" class="messages">
<div class="message message-notice">
<div><?= $block->escapeHtml(__('This operation can take a long time')) ?></div>
<div><?= $escaper->escapeHtml(__('This operation can take a long time')) ?></div>
</div>
</div>
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag('display: none;', 'div[data-id="information-dialog-category"]') ?>

<script type="text/x-magento-init">
{
"*": {
"categoryForm": {"refreshUrl": "<?= $block->escapeJs($block->escapeUrl($block->getRefreshPathUrl())) ?>"}
"categoryForm": {"refreshUrl": "<?= $escaper->escapeJs($escaper->escapeUrl($block->getRefreshPathUrl())) ?>"}
}
}
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
* See COPYING.txt for license details.
*/

/** @var \Magento\Catalog\Block\Adminhtml\Category\AssignProducts $block */
/** @var \Magento\Catalog\Block\Adminhtml\Category\Tab\Product $blockGrid */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
/**
* @var \Magento\Catalog\Block\Adminhtml\Category\AssignProducts $block
* @var \Magento\Catalog\Block\Adminhtml\Category\Tab\Product $blockGrid
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
*/

$blockGrid = $block->getBlockGrid();
$gridJsObjectName = $blockGrid->getJsObjectName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
* See COPYING.txt for license details.
*/

/** @var $block \Magento\Catalog\Block\Adminhtml\Category\Tree */
/** @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer */
/**
* @var \Magento\Catalog\Block\Adminhtml\Category\Tree $block
* @var \Magento\Framework\Escaper $escaper
* @var \Magento\Framework\View\Helper\SecureHtmlRenderer $secureRenderer
*/
?>
<div class="categories-side-col">
<div class="sidebar-actions">
Expand All @@ -16,9 +19,9 @@
</div>
<div class="tree-actions">
<?php if ($block->getRoot()):?>
<a id="colapseAll" href="#"><?= $block->escapeHtml(__('Collapse All')) ?></a>
<a id="colapseAll" href="#"><?= $escaper->escapeHtml(__('Collapse All')) ?></a>
<span class="separator">|</span>
<a id="expandAll" href="#"><?= $block->escapeHtml(__('Expand All')) ?></a>
<a id="expandAll" href="#"><?= $escaper->escapeHtml(__('Expand All')) ?></a>
<?php endif; ?>
</div>
<?php if ($block->getRoot()):?>
Expand All @@ -39,7 +42,7 @@

<div data-id="information-dialog-tree" class="messages">
<div class="message message-notice">
<div><?= $block->escapeHtml(__('This operation can take a long time')) ?></div>
<div><?= $escaper->escapeHtml(__('This operation can take a long time')) ?></div>
</div>
</div>
<?= /* @noEscape */ $secureRenderer->renderStyleAsTag(
Expand Down Expand Up @@ -183,7 +186,7 @@

if (!this.collapsed) {
this.collapsed = true;
this.loader.dataUrl = '{$block->escapeJs($block->getLoadTreeUrl(false))}';
this.loader.dataUrl = '{$escaper->escapeJs($block->getLoadTreeUrl(false))}';
this.request(this.loader.dataUrl, false);
}
},
Expand All @@ -192,7 +195,7 @@
this.expandAll();
if (this.collapsed) {
this.collapsed = false;
this.loader.dataUrl = '{$block->escapeJs($block->getLoadTreeUrl(true))}';
this.loader.dataUrl = '{$escaper->escapeJs($block->getLoadTreeUrl(true))}';
this.request(this.loader.dataUrl, false);
}
},
Expand Down Expand Up @@ -227,7 +230,7 @@
if (tree && switcherParams) {
var url;
if (switcherParams.useConfirm) {
if (!confirm("{$block->escapeJs(__(
if (!confirm("{$escaper->escapeJs(__(
'Please confirm site switching. All data that hasn\'t been saved will be lost.'
))}")) {
return false;
Expand Down Expand Up @@ -272,7 +275,7 @@
}
});
} else {
var baseUrl = '{$block->escapeJs($block->getEditUrl())}';
var baseUrl = '{$escaper->escapeJs($block->getEditUrl())}';
var urlExt = switcherParams.scopeParams + 'id/' + tree.currentNodeId + '/';
url = parseSidUrl(baseUrl, urlExt);
setLocation(url);
Expand Down Expand Up @@ -324,7 +327,7 @@ endif;

jQuery(function () {
categoryLoader = new Ext.tree.TreeLoader({
dataUrl: '{$block->escapeJs($block->getLoadTreeUrl())}'
dataUrl: '{$escaper->escapeJs($block->getLoadTreeUrl())}'
});

categoryLoader.processResponse = function (response, parent, callback) {
Expand Down Expand Up @@ -409,11 +412,11 @@ endif;
script;
$scriptString .= '
rootVisible: \'' . ($block->getRoot()->getIsVisible() ? 'true' : 'false') . '\',
useAjax: ' . $block->escapeJs($block->getUseAjax()) . ',
switchTreeUrl: \'' . $block->escapeJs($block->escapeUrl($block->getSwitchTreeUrl())) .'\',
editUrl: \'' . $block->escapeJs($block->escapeUrl($block->getEditUrl())) .'\',
useAjax: ' . $escaper->escapeJs($block->getUseAjax()) . ',
switchTreeUrl: \'' . $escaper->escapeJs($escaper->escapeUrl($block->getSwitchTreeUrl())) .'\',
editUrl: \'' . $escaper->escapeJs($escaper->escapeUrl($block->getEditUrl())) .'\',
currentNodeId: ' . (int)$block->getCategoryId() . ',
baseUrl: \'' . $block->escapeJs($block->escapeUrl($block->getEditUrl())) . '\'
baseUrl: \'' . $escaper->escapeJs($escaper->escapeUrl($block->getEditUrl())) . '\'
};

defaultLoadTreeParams = {
Expand Down Expand Up @@ -504,7 +507,7 @@ script;
click: function () {
(function ($) {
$.ajax({
url: '{$block->escapeJs($block->getMoveUrl())}',
url: '{$escaper->escapeJs($block->getMoveUrl())}',
method: 'POST',
data: registry.get('pd'),
showLoader: true
Expand Down
Loading