Skip to content

Commit 1618b83

Browse files
authored
PropertyString: decode HTML entities appropriately. (#4321)
1 parent 6930e60 commit 1618b83

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

module/VuFind/src/VuFind/String/PropertyString.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ public function __construct(protected string $string, protected array $propertie
6666
*/
6767
public static function fromHtml(string $html, array $properties = []): PropertyString
6868
{
69-
return (new PropertyString(strip_tags($html), $properties))->setHtml($html);
69+
$decodedHtml = html_entity_decode(strip_tags($html));
70+
return (new PropertyString($decodedHtml, $properties))->setHtml($html);
7071
}
7172

7273
/**

module/VuFind/tests/unit-tests/src/VuFindTest/String/PropertyStringTest.php

+7
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,13 @@ public static function fromHtmlProvider(): array
114114
'<strong>HTML</strong> string',
115115
['__html' => '<strong>HTML</strong> string'],
116116
],
117+
'HTML string containing entities' => [
118+
'<i>Dungeons &amp; Dragons</i>',
119+
[],
120+
'Dungeons & Dragons',
121+
'<i>Dungeons &amp; Dragons</i>',
122+
['__html' => '<i>Dungeons &amp; Dragons</i>'],
123+
],
117124
];
118125
}
119126

module/VuFind/tests/unit-tests/src/VuFindTest/View/Helper/Root/EscapeOrCleanHtmlTest.php

+4
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static function escapeOrCleanHtmlProvider(): array
5656
{
5757
$link = '<a href="https://vufind.org/">VuFind</a>';
5858
$div = '<div>Div</div>';
59+
$dnd = '<i>Dungeons &amp; Dragons</i>';
5960
return [
6061
'plain string' => ['plain string', null, null, 'default', [], 'plain string'],
6162
'link' => [$link, null, null, 'default', [], htmlentities($link)],
@@ -75,6 +76,9 @@ public static function escapeOrCleanHtmlProvider(): array
7576
'div as PropertyString, allow HTML, rendered in heading' => [
7677
PropertyString::fromHtml($div), null, true, 'heading', [], 'Div',
7778
],
79+
'HTML containing entity, disallow HTML' => [
80+
PropertyString::fromHtml($dnd), null, false, 'heading', [], 'Dungeons &amp; Dragons',
81+
],
7882
];
7983
}
8084

0 commit comments

Comments
 (0)