|
10 | 10 | use Magento\Catalog\Model\CategoryFactory; |
11 | 11 | use Magento\Framework\App\Helper\AbstractHelper; |
12 | 12 | use Magento\Framework\App\Helper\Context; |
| 13 | +use Magento\Framework\App\ObjectManager; |
13 | 14 | use Magento\Framework\Data\CollectionFactory; |
14 | 15 | use Magento\Framework\Data\Tree\Node\Collection; |
| 16 | +use Magento\Framework\Escaper; |
15 | 17 | use Magento\Framework\Exception\NoSuchEntityException; |
16 | 18 | use Magento\Framework\ObjectManager\ResetAfterRequestInterface; |
17 | 19 | use Magento\Store\Model\ScopeInterface; |
@@ -63,24 +65,33 @@ class Category extends AbstractHelper implements ResetAfterRequestInterface |
63 | 65 | */ |
64 | 66 | protected $categoryRepository; |
65 | 67 |
|
| 68 | + /** |
| 69 | + * @var Escaper|null |
| 70 | + */ |
| 71 | + private ?Escaper $escaper; |
| 72 | + |
66 | 73 | /** |
67 | 74 | * @param Context $context |
68 | 75 | * @param CategoryFactory $categoryFactory |
69 | 76 | * @param StoreManagerInterface $storeManager |
70 | 77 | * @param CollectionFactory $dataCollectionFactory |
71 | 78 | * @param CategoryRepositoryInterface $categoryRepository |
| 79 | + * @param Escaper|null $escaper |
72 | 80 | */ |
73 | 81 | public function __construct( |
74 | 82 | Context $context, |
75 | 83 | CategoryFactory $categoryFactory, |
76 | 84 | StoreManagerInterface $storeManager, |
77 | 85 | CollectionFactory $dataCollectionFactory, |
78 | | - CategoryRepositoryInterface $categoryRepository |
| 86 | + CategoryRepositoryInterface $categoryRepository, |
| 87 | + ?Escaper $escaper = null |
79 | 88 | ) { |
80 | 89 | $this->_categoryFactory = $categoryFactory; |
81 | 90 | $this->_storeManager = $storeManager; |
82 | 91 | $this->_dataCollectionFactory = $dataCollectionFactory; |
83 | 92 | $this->categoryRepository = $categoryRepository; |
| 93 | + $this->escaper = $escaper ?: ObjectManager::getInstance()->get(Escaper::class); |
| 94 | + |
84 | 95 | parent::__construct($context); |
85 | 96 | } |
86 | 97 |
|
@@ -204,6 +215,7 @@ public function getCanonicalUrl(string $categoryUrl): string |
204 | 215 | if ($params && isset($params['p'])) { |
205 | 216 | $categoryUrl = $categoryUrl . '?p=' . $params['p']; |
206 | 217 | } |
207 | | - return $categoryUrl; |
| 218 | + |
| 219 | + return $this->escaper->escapeUrl($categoryUrl); |
208 | 220 | } |
209 | 221 | } |
0 commit comments