mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge branch '5.2' into 5
This commit is contained in:
commit
3829160151
@ -32,7 +32,7 @@ class HTMLValue extends ViewableData
|
|||||||
*/
|
*/
|
||||||
public function setContent($content)
|
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]);
|
$html5 = new HTML5(['disable_html_ns' => true]);
|
||||||
$document = $html5->loadHTML(
|
$document = $html5->loadHTML(
|
||||||
'<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>' .
|
'<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.');
|
$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