Skip to content

Commit ceda589

Browse files
tranthienbinh1989nishant04412
authored andcommitted
AC-14712 improve category view
1 parent 252fda5 commit ceda589

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

app/code/Magento/Catalog/Helper/Category.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@
1010
use Magento\Catalog\Model\CategoryFactory;
1111
use Magento\Framework\App\Helper\AbstractHelper;
1212
use Magento\Framework\App\Helper\Context;
13+
use Magento\Framework\App\ObjectManager;
1314
use Magento\Framework\Data\CollectionFactory;
1415
use Magento\Framework\Data\Tree\Node\Collection;
16+
use Magento\Framework\Escaper;
1517
use Magento\Framework\Exception\NoSuchEntityException;
1618
use Magento\Framework\ObjectManager\ResetAfterRequestInterface;
1719
use Magento\Store\Model\ScopeInterface;
@@ -63,24 +65,33 @@ class Category extends AbstractHelper implements ResetAfterRequestInterface
6365
*/
6466
protected $categoryRepository;
6567

68+
/**
69+
* @var Escaper|null
70+
*/
71+
private ?Escaper $escaper;
72+
6673
/**
6774
* @param Context $context
6875
* @param CategoryFactory $categoryFactory
6976
* @param StoreManagerInterface $storeManager
7077
* @param CollectionFactory $dataCollectionFactory
7178
* @param CategoryRepositoryInterface $categoryRepository
79+
* @param Escaper|null $escaper
7280
*/
7381
public function __construct(
7482
Context $context,
7583
CategoryFactory $categoryFactory,
7684
StoreManagerInterface $storeManager,
7785
CollectionFactory $dataCollectionFactory,
78-
CategoryRepositoryInterface $categoryRepository
86+
CategoryRepositoryInterface $categoryRepository,
87+
?Escaper $escaper = null
7988
) {
8089
$this->_categoryFactory = $categoryFactory;
8190
$this->_storeManager = $storeManager;
8291
$this->_dataCollectionFactory = $dataCollectionFactory;
8392
$this->categoryRepository = $categoryRepository;
93+
$this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class);
94+
8495
parent::__construct($context);
8596
}
8697

@@ -204,6 +215,7 @@ public function getCanonicalUrl(string $categoryUrl): string
204215
if ($params && isset($params['p'])) {
205216
$categoryUrl = $categoryUrl . '?p=' . $params['p'];
206217
}
207-
return $categoryUrl;
218+
219+
return $this->escaper->escapeUrl($categoryUrl);
208220
}
209221
}

0 commit comments

Comments
 (0)