Skip to content

Commit 81ba50d

Browse files
committed
Merge remote-tracking branch 'origin/2.4.8-beta2-develop' into AC-12133-v2
2 parents b99417e + 87d012e commit 81ba50d

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

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

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe.
4+
* All Rights Reserved.
55
*/
6-
76
declare(strict_types=1);
87

98
namespace Magento\Framework\Test\Unit\Validator\HTML;
@@ -16,6 +15,49 @@
1615

1716
class ConfigurableWYSIWYGValidatorTest extends TestCase
1817
{
18+
/**
19+
* @var ConfigurableWYSIWYGValidator
20+
*/
21+
private ConfigurableWYSIWYGValidator $validator;
22+
23+
protected function setUp(): void
24+
{
25+
$allowedTags = ['p', 'a', 'div'];
26+
$allowedAttributes = ['href', 'title'];
27+
$attributesAllowedByTags = ['a' => ['href', 'title']];
28+
$attributeValidators = [];
29+
$tagValidators = [];
30+
31+
$this->validator = new ConfigurableWYSIWYGValidator(
32+
$allowedTags,
33+
$allowedAttributes,
34+
$attributesAllowedByTags,
35+
$attributeValidators,
36+
$tagValidators
37+
);
38+
}
39+
40+
/**
41+
* Test that the validator error message does not contain duplicated tags body and html.
42+
*
43+
* @return void
44+
* @throws ValidationException
45+
*/
46+
public function testValidateThrowsExceptionForDisallowedTags()
47+
{
48+
$this->expectException(ValidationException::class);
49+
$this->expectExceptionMessageMatches('/^(Allowed HTML tags are: p, a, div, body, html)*$/');
50+
51+
$validHtml = '<html><body>test1</body></html>';
52+
$this->validator->validate($validHtml);
53+
$validHtml = '<html><body>test2</body></html>';
54+
$this->validator->validate($validHtml);
55+
$validHtml = '<html><body>test3</body></html>';
56+
$this->validator->validate($validHtml);
57+
$invalidHtml = '<html><body><script>alert("XSS")</script></body></html>';
58+
$this->validator->validate($invalidHtml);
59+
}
60+
1961
/**
2062
* Configurations to test.
2163
*

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66

77
declare(strict_types=1);
@@ -110,7 +110,8 @@ public function validate(string $content): void
110110
private function validateConfigured(\DOMXPath $xpath): void
111111
{
112112
//Validating tags
113-
$this->allowedTags = array_merge($this->allowedTags, ["body", "html"]);
113+
$this->allowedTags['body'] = 'body';
114+
$this->allowedTags['html'] = 'html';
114115
$found = $xpath->query(
115116
'//*['
116117
. implode(

0 commit comments

Comments
 (0)