Skip to content

Commit

Permalink
Merge branch '5' into 6
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jul 9, 2024
2 parents d96d852 + 3829160 commit b405c4d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/ORM/DataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -2512,7 +2512,7 @@ public function scaffoldFormFieldForHasOne(
$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;
Expand Down
2 changes: 1 addition & 1 deletion src/View/Parsers/HTMLValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct($fragment = null)
*/
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>' .
Expand Down
8 changes: 6 additions & 2 deletions tests/php/Forms/HTMLEditor/HTMLEditorFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ public function testReadonlyField()
$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>
Expand All @@ -199,7 +201,9 @@ public function testReadonlyField()
$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=&quot;/assets/HTMLEditorFieldTest/f5c7c2f814/example.jpg&quot; width=&quot;10&quot; height=&quot;20&quot; id=&quot;{$fileID}&quot;]" />
Expand Down
28 changes: 28 additions & 0 deletions tests/php/View/Parsers/HTMLValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,32 @@ public function testValidHTMLInNoscriptTags()
$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');
}
}

0 comments on commit b405c4d

Please sign in to comment.