mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Merge branch '5' into 6
This commit is contained in:
commit
b405c4dbb6
@ -2512,7 +2512,7 @@ class DataObject extends ViewableData implements DataObjectInterface, i18nEntity
|
||||
$list = DataList::create(static::class);
|
||||
$threshold = DBForeignKey::config()->get('dropdown_field_threshold');
|
||||
$overThreshold = $list->count() > $threshold;
|
||||
$field = SearchableDropdownField::create($fieldName, $fieldTitle, $list, $labelField)
|
||||
$field = SearchableDropdownField::create($fieldName, $fieldTitle, $list, $ownerRecord->{$relationName . 'ID'}, $labelField)
|
||||
->setIsLazyLoaded($overThreshold)
|
||||
->setLazyLoadLimit($threshold);
|
||||
return $field;
|
||||
|
@ -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>' .
|
||||
|
@ -182,7 +182,9 @@ class HTMLEditorFieldTest extends FunctionalTest
|
||||
$this->assertEquals(
|
||||
<<<EOS
|
||||
<span class="readonly typography" id="Content">
|
||||
<img src="/assets/HTMLEditorFieldTest/f5c7c2f814/example__ResizedImageWzEwLDIwXQ.jpg" alt="" width="10" height="20" loading="lazy">
|
||||
<img width="10" height="20" alt="" src="/assets/HTMLEditorFieldTest/f5c7c2f814/example__ResizedImageWzEwLDIwXQ.jpg" loading="lazy">
|
||||
|
||||
|
||||
</span>
|
||||
|
||||
|
||||
@ -199,7 +201,9 @@ EOS
|
||||
$this->assertEquals(
|
||||
<<<EOS
|
||||
<span class="readonly typography" id="Content">
|
||||
<img src="/assets/HTMLEditorFieldTest/f5c7c2f814/example__ResizedImageWzEwLDIwXQ.jpg" alt="" width="10" height="20" loading="lazy">
|
||||
<img width="10" height="20" alt="" src="/assets/HTMLEditorFieldTest/f5c7c2f814/example__ResizedImageWzEwLDIwXQ.jpg" loading="lazy">
|
||||
|
||||
|
||||
</span>
|
||||
|
||||
<input type="hidden" name="Content" value="[image src="/assets/HTMLEditorFieldTest/f5c7c2f814/example.jpg" width="10" height="20" id="{$fileID}"]" />
|
||||
|
@ -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…
x
Reference in New Issue
Block a user