Skip to content

Commit 31edf15

Browse files
committed
MC-16607: Fix Unrelated Static Test Failures
- fix tests failures
1 parent d06428f commit 31edf15

File tree

3 files changed

+58
-38
lines changed

3 files changed

+58
-38
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\PageBuilder\Plugin\Filter;
9+
10+
use Magento\Store\Model\Store;
11+
12+
/**
13+
* Plugin to the template filter to escape custom variable directives
14+
*/
15+
class CustomVarTemplatePlugin
16+
{
17+
/**
18+
* @var \Magento\Framework\Escaper
19+
*/
20+
private $escaper;
21+
22+
/**
23+
* @param \Magento\Framework\Escaper $escaper
24+
*/
25+
public function __construct(
26+
\Magento\Framework\Escaper $escaper
27+
) {
28+
$this->escaper = $escaper;
29+
}
30+
31+
/**
32+
* Determine if custom variable directive's return value needs to be escaped and do so if true
33+
*
34+
* @param \Magento\Framework\Filter\Template $subject
35+
* @param \Closure $proceed
36+
* @param string[] $construction
37+
* @return string
38+
*/
39+
public function aroundCustomvarDirective(
40+
\Magento\Framework\Filter\Template $subject,
41+
\Closure $proceed,
42+
$construction
43+
) {
44+
// Determine the need to escape the return value of observed method.
45+
// Admin context requires store ID of 0; in that context return value should be escaped
46+
$shouldEscape = $subject->getStoreId() !== null && (int) $subject->getStoreId() === Store::DEFAULT_STORE_ID;
47+
48+
if (!$shouldEscape) {
49+
return $proceed($construction);
50+
}
51+
52+
$result = $proceed($construction);
53+
return $this->escaper->escapeHtml($result);
54+
}
55+
}

app/code/Magento/PageBuilder/Plugin/Filter/TemplatePlugin.php

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@
77

88
namespace Magento\PageBuilder\Plugin\Filter;
99

10-
use Magento\Store\Model\Store;
11-
1210
/**
1311
* Plugin to the template filter to process any background images added by Page Builder
1412
*/
@@ -18,11 +16,6 @@ class TemplatePlugin
1816

1917
const HTML_CONTENT_TYPE_PATTERN = '/data-content-type="html"/si';
2018

21-
/**
22-
* @var \Magento\Framework\Escaper
23-
*/
24-
private $escaper;
25-
2619
/**
2720
* @var \Magento\Framework\View\ConfigInterface
2821
*/
@@ -52,22 +45,17 @@ class TemplatePlugin
5245
* @param \Psr\Log\LoggerInterface $logger
5346
* @param \Magento\Framework\View\ConfigInterface $viewConfig
5447
* @param \Magento\Framework\Math\Random $mathRandom
55-
* @param \Magento\Framework\Escaper|null $escaper
5648
* @param \Magento\Framework\Serialize\Serializer\Json|null $json
5749
*/
5850
public function __construct(
5951
\Psr\Log\LoggerInterface $logger,
6052
\Magento\Framework\View\ConfigInterface $viewConfig,
6153
\Magento\Framework\Math\Random $mathRandom,
62-
\Magento\Framework\Escaper $escaper = null,
6354
\Magento\Framework\Serialize\Serializer\Json $json = null
6455
) {
6556
$this->logger = $logger;
6657
$this->viewConfig = $viewConfig;
6758
$this->mathRandom = $mathRandom;
68-
$this->escaper = $escaper ?? \Magento\Framework\App\ObjectManager::getInstance()->get(
69-
\Magento\Framework\Escaper::class
70-
);
7159
$this->json = $json ?? \Magento\Framework\App\ObjectManager::getInstance()->get(
7260
\Magento\Framework\Serialize\Serializer\Json::class
7361
);
@@ -127,32 +115,6 @@ public function afterFilter(\Magento\Framework\Filter\Template $subject, string
127115
return $result;
128116
}
129117

130-
/**
131-
* Determine if custom variable directive's return value needs to be escaped and do so if true
132-
*
133-
* @param \Magento\Framework\Filter\Template $subject
134-
* @param \Closure $proceed
135-
* @param string[] $construction
136-
* @return string
137-
*/
138-
public function aroundCustomvarDirective(
139-
\Magento\Framework\Filter\Template $subject,
140-
\Closure $proceed,
141-
$construction
142-
) {
143-
// Determine the need to escape the return value of observed method.
144-
// Admin context requires store ID of 0; in that context return value should be escaped
145-
$shouldEscape = $subject->getStoreId() !== null && (int) $subject->getStoreId() === Store::DEFAULT_STORE_ID;
146-
147-
if (!$shouldEscape) {
148-
return $proceed($construction);
149-
}
150-
151-
$result = $proceed($construction);
152-
153-
return $this->escaper->escapeHtml($result);
154-
}
155-
156118
/**
157119
* Create a DOM document from a given string
158120
*

app/code/Magento/PageBuilder/etc/frontend/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,7 @@
1212
<type name="Magento\Framework\Filter\Template">
1313
<plugin name="convertBackgroundImages" type="Magento\PageBuilder\Plugin\Filter\TemplatePlugin"/>
1414
</type>
15+
<type name="Magento\Framework\Filter\Template">
16+
<plugin name="escapeCustomVarDirectives" type="Magento\PageBuilder\Plugin\Filter\CustomVarTemplatePlugin"/>
17+
</type>
1518
</config>

0 commit comments

Comments
 (0)