Skip to content

Commit

Permalink
Merge pull request #4412 from magento-obsessive-owls/MC-16926
Browse files Browse the repository at this point in the history
  • Loading branch information
danmooney2 authored Jun 28, 2019
2 parents 26ab857 + cb16f44 commit 5f446e3
Show file tree
Hide file tree
Showing 61 changed files with 840 additions and 228 deletions.
15 changes: 13 additions & 2 deletions app/code/Magento/AdminNotification/Model/Feed.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ class Feed extends \Magento\Framework\Model\AbstractModel

const XML_LAST_UPDATE_PATH = 'system/adminnotification/last_update';

/**
* @var \Magento\Framework\Escaper
*/
private $escaper;

/**
* Feed url
*
Expand Down Expand Up @@ -77,6 +82,7 @@ class Feed extends \Magento\Framework\Model\AbstractModel
* @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
* @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
* @param array $data
* @param \Magento\Framework\Escaper|null $escaper
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
Expand All @@ -90,7 +96,8 @@ public function __construct(
\Magento\Framework\UrlInterface $urlBuilder,
\Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
array $data = []
array $data = [],
\Magento\Framework\Escaper $escaper = null
) {
parent::__construct($context, $registry, $resource, $resourceCollection, $data);
$this->_backendConfig = $backendConfig;
Expand All @@ -99,12 +106,16 @@ public function __construct(
$this->_deploymentConfig = $deploymentConfig;
$this->productMetadata = $productMetadata;
$this->urlBuilder = $urlBuilder;
$this->escaper = $escaper ?? \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\Escaper::class
);
}

/**
* Init model
*
* @return void
* phpcs:disable Magento2.CodeAnalysis.EmptyBlock
*/
protected function _construct()
{
Expand Down Expand Up @@ -255,6 +266,6 @@ public function getFeedXml()
*/
private function escapeString(\SimpleXMLElement $data)
{
return htmlspecialchars((string)$data);
return $this->escaper->escapeHtml((string)$data);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ protected function setUp()
->setMethods(['getComment', 'getHtmlId', 'getName'])
->disableOriginalConstructor()
->getMock();

$objectManager = new ObjectManager($this);
$escaper = $objectManager->getObject(\Magento\Framework\Escaper::class);
$objectManager->setBackwardCompatibleProperty(
$this->abstractElementMock,
'_escaper',
$escaper
);

$this->contextMock = $this->getMockBuilder(Context::class)
->setMethods(['getLocaleDate'])
->disableOriginalConstructor()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ protected function setUp()
->setMethods(['getComment', 'getHtmlId', 'getName'])
->disableOriginalConstructor()
->getMock();

$objectManager = new ObjectManager($this);
$escaper = $objectManager->getObject(\Magento\Framework\Escaper::class);
$objectManager->setBackwardCompatibleProperty(
$this->abstractElementMock,
'_escaper',
$escaper
);

$this->formMock = $this->getMockBuilder(Form::class)
->disableOriginalConstructor()
->getMock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ protected function setUp()
->setMethods(['getComment', 'getLabel', 'getHint', 'getHtmlId', 'getName'])
->disableOriginalConstructor()
->getMock();

$objectManager = new ObjectManager($this);
$escaper = $objectManager->getObject(\Magento\Framework\Escaper::class);
$objectManager->setBackwardCompatibleProperty(
$this->abstractElementMock,
'_escaper',
$escaper
);

$this->contextMock = $this->getMockBuilder(Context::class)
->disableOriginalConstructor()
->getMock();
Expand Down
45 changes: 42 additions & 3 deletions app/code/Magento/Catalog/Block/Adminhtml/Product/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,22 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block\Adminhtml\Product;

/**
* Customer edit block
*
* @author Magento Core Team <[email protected]>
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* @SuppressWarnings(PHPMD.RequestAwareBlockMethod)
*/
namespace Magento\Catalog\Block\Adminhtml\Product;

class Edit extends \Magento\Backend\Block\Widget
{
/**
* @var \Magento\Framework\Escaper
*/
private $escaper;

/**
* @var string
*/
Expand Down Expand Up @@ -47,6 +52,7 @@ class Edit extends \Magento\Backend\Block\Widget
* @param \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory
* @param \Magento\Framework\Registry $registry
* @param \Magento\Catalog\Helper\Product $productHelper
* @param \Magento\Framework\Escaper $escaper
* @param array $data
*/
public function __construct(
Expand All @@ -55,16 +61,20 @@ public function __construct(
\Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory,
\Magento\Framework\Registry $registry,
\Magento\Catalog\Helper\Product $productHelper,
\Magento\Framework\Escaper $escaper,
array $data = []
) {
$this->_productHelper = $productHelper;
$this->_attributeSetFactory = $attributeSetFactory;
$this->_coreRegistry = $registry;
$this->jsonEncoder = $jsonEncoder;
$this->escaper = $escaper;
parent::__construct($context, $data);
}

/**
* Edit Product constructor
*
* @return void
*/
protected function _construct()
Expand Down Expand Up @@ -144,6 +154,8 @@ protected function _prepareLayout()
}

/**
* Retrieve back button html
*
* @return string
*/
public function getBackButtonHtml()
Expand All @@ -152,6 +164,8 @@ public function getBackButtonHtml()
}

/**
* Retrieve cancel button html
*
* @return string
*/
public function getCancelButtonHtml()
Expand All @@ -160,6 +174,8 @@ public function getCancelButtonHtml()
}

/**
* Retrieve save button html
*
* @return string
*/
public function getSaveButtonHtml()
Expand All @@ -168,6 +184,8 @@ public function getSaveButtonHtml()
}

/**
* Retrieve save and edit button html
*
* @return string
*/
public function getSaveAndEditButtonHtml()
Expand All @@ -176,6 +194,8 @@ public function getSaveAndEditButtonHtml()
}

/**
* Retrieve delete button html
*
* @return string
*/
public function getDeleteButtonHtml()
Expand All @@ -194,6 +214,8 @@ public function getSaveSplitButtonHtml()
}

/**
* Retrieve validation url
*
* @return string
*/
public function getValidationUrl()
Expand All @@ -202,6 +224,8 @@ public function getValidationUrl()
}

/**
* Retrieve save url
*
* @return string
*/
public function getSaveUrl()
Expand All @@ -210,6 +234,8 @@ public function getSaveUrl()
}

/**
* Retrieve save and continue url
*
* @return string
*/
public function getSaveAndContinueUrl()
Expand All @@ -221,6 +247,8 @@ public function getSaveAndContinueUrl()
}

/**
* Retrieve product id
*
* @return mixed
*/
public function getProductId()
Expand All @@ -229,6 +257,8 @@ public function getProductId()
}

/**
* Retrieve product set id
*
* @return mixed
*/
public function getProductSetId()
Expand All @@ -241,6 +271,8 @@ public function getProductSetId()
}

/**
* Retrieve duplicate url
*
* @return string
*/
public function getDuplicateUrl()
Expand All @@ -249,6 +281,8 @@ public function getDuplicateUrl()
}

/**
* Retrieve product header
*
* @deprecated 101.1.0
* @return string
*/
Expand All @@ -263,6 +297,8 @@ public function getHeader()
}

/**
* Get product attribute set name
*
* @return string
*/
public function getAttributeSetName()
Expand All @@ -275,11 +311,14 @@ public function getAttributeSetName()
}

/**
* Retrieve id of selected tab
*
* @return string
*/
public function getSelectedTabId()
{
return addslashes(htmlspecialchars($this->getRequest()->getParam('tab')));
// phpcs:ignore Magento2.Functions.DiscouragedFunction
return addslashes($this->escaper->escapeHtml($this->getRequest()->getParam('tab')));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
*/
class Action extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
{
/**
* @var \Magento\Framework\Escaper
*/
private $escaper;

/**
* Core registry
*
Expand All @@ -21,17 +26,24 @@ class Action extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Abstract
* @param \Magento\Backend\Block\Context $context
* @param \Magento\Framework\Registry $registry
* @param array $data
* @param \Magento\Framework\Escaper|null $escaper
*/
public function __construct(
\Magento\Backend\Block\Context $context,
\Magento\Framework\Registry $registry,
array $data = []
array $data = [],
\Magento\Framework\Escaper $escaper = null
) {
$this->_coreRegistry = $registry;
$this->escaper = $escaper ?? \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\Escaper::class
);
parent::__construct($context, $data);
}

/**
* Render actions
*
* @param \Magento\Framework\DataObject $row
* @return string
*/
Expand All @@ -57,15 +69,20 @@ public function render(\Magento\Framework\DataObject $row)
}

/**
* Retrieve escaped value
*
* @param string $value
* @return string
*/
protected function _getEscapedValue($value)
{
return addcslashes(htmlspecialchars($value), '\\\'');
// phpcs:ignore Magento2.Functions.DiscouragedFunction
return addcslashes($this->escaper->escapeHtml($value), '\\\'');
}

/**
* Actions to html
*
* @param array $actions
* @return string
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ class Description extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\Abs
*/
public function render(\Magento\Framework\DataObject $row)
{
return nl2br(htmlspecialchars($row->getData($this->getColumn()->getIndex())));
return nl2br($this->escapeHtml($row->getData($this->getColumn()->getIndex())));
}
}
Loading

0 comments on commit 5f446e3

Please sign in to comment.