mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
FIX Don't strip <header>
tag from HTMLValue
(#11302)
This commit is contained in:
parent
1943f9d417
commit
c13ec34113
@ -32,7 +32,7 @@ class HTMLValue extends ViewableData
|
||||
*/
|
||||
public function setContent($content)
|
||||
{
|
||||
$content = preg_replace('#</?(html|head|body)[^>]*>#si', '', $content);
|
||||
$content = preg_replace('#</?(html|head(?!er)|body)[^>]*>#si', '', $content);
|
||||
$html5 = new HTML5(['disable_html_ns' => true]);
|
||||
$document = $html5->loadHTML(
|
||||
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>' .
|
||||
|
@ -160,4 +160,32 @@ class HTMLValueTest extends SapphireTest
|
||||
$this->assertEquals($noscript, $value->getContent(), 'Child tags are left untouched in noscript tags.');
|
||||
}
|
||||
}
|
||||
|
||||
public function provideOnlyStripIntendedTags(): array
|
||||
{
|
||||
return [
|
||||
[
|
||||
'input' => '<html><head></head><body><div><p>blahblah</p></div></body></html>',
|
||||
'expected' => '<div><p>blahblah</p></div>',
|
||||
],
|
||||
[
|
||||
'input' => '<html><head></head><body><header></header><div><p>blahblah</p></div></body></html>',
|
||||
'expected' => '<header></header><div><p>blahblah</p></div>',
|
||||
],
|
||||
[
|
||||
'input' => '<html some-attribute another-attribute="something"><head></head><body><div><p>blahblah</p></div></body></html>',
|
||||
'expected' => '<div><p>blahblah</p></div>',
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider provideOnlyStripIntendedTags
|
||||
*/
|
||||
public function testOnlyStripIntendedTags(string $input, string $expected): void
|
||||
{
|
||||
$value = new HTMLValue();
|
||||
$value->setContent($input);
|
||||
$this->assertEquals($expected, $value->getContent(), 'Invalid HTML can be parsed');
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user