Skip to content

Commit 2bffa45

Browse files
Merge pull request #9251 from magento-cia/cia-2.4.8-beta1-develop-bugfix-09072024
Cia 2.4.8 beta1 develop bugfix 09072024
2 parents bd8c1df + 93e45c5 commit 2bffa45

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

lib/internal/Magento/Framework/Test/Unit/Validator/HTML/ConfigurableWYSIWYGValidatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ class ConfigurableWYSIWYGValidatorTest extends TestCase
2626
public static function getConfigurations(): array
2727
{
2828
return [
29-
'no-html' => [['div'], [], [], 'just text', true, [], []],
30-
'allowed-tag' => [['div'], [], [], 'just text and <div>a div</div>', true, [], []],
29+
'no-html' => [['div'], [], [], 'just text', false, [], []],
30+
'allowed-tag' => [['div'], [], [], 'just text and <div>a div</div>', false, [], []],
3131
'restricted-tag' => [
3232
['div', 'p'],
3333
[],

lib/internal/Magento/Framework/Validator/HTML/ConfigurableWYSIWYGValidator.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ class ConfigurableWYSIWYGValidator implements WYSIWYGValidatorInterface
2323
. '((\\\\x6A\\\\x61\\\\x76\\\\x61\\\\x73\\\\x63\\\\x72\\\\x69\\\\x70\\\\x74(\\\\x3a|:|%3A))|'
2424
. '(\\\\x64\\\\x61\\\\x74\\\\x61(\\\\x3a|:|%3A)))/i';
2525

26+
/**
27+
* @var string
28+
*/
29+
private static string $contentFiltrationPattern = "/(<body)/i";
30+
2631
/**
2732
* @var string[]
2833
*/
@@ -105,6 +110,7 @@ public function validate(string $content): void
105110
private function validateConfigured(\DOMXPath $xpath): void
106111
{
107112
//Validating tags
113+
$this->allowedTags = array_merge($this->allowedTags, ["body", "html"]);
108114
$found = $xpath->query(
109115
'//*['
110116
. implode(
@@ -113,7 +119,7 @@ private function validateConfigured(\DOMXPath $xpath): void
113119
function (string $tag): string {
114120
return "name() != '$tag'";
115121
},
116-
array_merge($this->allowedTags, ['body', 'html'])
122+
$this->allowedTags
117123
)
118124
)
119125
.']'
@@ -243,7 +249,9 @@ function () use (&$loaded) {
243249
$loaded = false;
244250
}
245251
);
246-
$loaded = $dom->loadHTML("<html><body>$content</body></html>");
252+
$matches = [];
253+
preg_match_all(self::$contentFiltrationPattern, $content, $matches);
254+
$loaded = !(count($matches[0]) > 1) && $dom->loadHTML($content, LIBXML_HTML_NOIMPLIED);
247255
restore_error_handler();
248256
if (!$loaded) {
249257
throw new ValidationException(__('Invalid HTML content provided'));

0 commit comments

Comments
 (0)