mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #10732 from creative-commoners/pulls/5.0/embed
API Remove configurability of attributes
This commit is contained in:
commit
62f6177ec1
@ -28,22 +28,6 @@ class EmbedShortcodeProvider implements ShortcodeHandler
|
|||||||
{
|
{
|
||||||
use Configurable;
|
use Configurable;
|
||||||
|
|
||||||
/**
|
|
||||||
* A whitelist of shortcode attributes which are allowed in the resultant markup.
|
|
||||||
* Note that the tinymce plugin restricts attributes on the client-side separately.
|
|
||||||
*
|
|
||||||
* @config
|
|
||||||
* @deprecated 4.12.0 Removed without equivalent functionality to replace it
|
|
||||||
*/
|
|
||||||
private static array $attribute_whitelist = [
|
|
||||||
'url',
|
|
||||||
'thumbnail',
|
|
||||||
'class',
|
|
||||||
'width',
|
|
||||||
'height',
|
|
||||||
'caption',
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the list of shortcodes provided by this handler
|
* Gets the list of shortcodes provided by this handler
|
||||||
*
|
*
|
||||||
@ -262,8 +246,17 @@ class EmbedShortcodeProvider implements ShortcodeHandler
|
|||||||
*/
|
*/
|
||||||
private static function buildAttributeListFromArguments(array $arguments, array $exclude = []): ArrayList
|
private static function buildAttributeListFromArguments(array $arguments, array $exclude = []): ArrayList
|
||||||
{
|
{
|
||||||
|
// A whitelist of shortcode attributes which are allowed in the resultant markup.
|
||||||
|
// Note that the tinymce plugin restricts attributes on the client-side separately.
|
||||||
|
$whitelist = [
|
||||||
|
'url',
|
||||||
|
'thumbnail',
|
||||||
|
'class',
|
||||||
|
'width',
|
||||||
|
'height',
|
||||||
|
'caption'
|
||||||
|
];
|
||||||
// Clean out any empty arguments and anything not whitelisted
|
// Clean out any empty arguments and anything not whitelisted
|
||||||
$whitelist = static::config()->get('attribute_whitelist');
|
|
||||||
$arguments = array_filter($arguments, function ($value, $key) use ($whitelist) {
|
$arguments = array_filter($arguments, function ($value, $key) use ($whitelist) {
|
||||||
return in_array($key, $whitelist) && strlen(trim($value ?? ''));
|
return in_array($key, $whitelist) && strlen(trim($value ?? ''));
|
||||||
}, ARRAY_FILTER_USE_BOTH);
|
}, ARRAY_FILTER_USE_BOTH);
|
||||||
|
@ -217,37 +217,4 @@ class EmbedShortcodeProviderTest extends EmbedUnitTest
|
|||||||
$html
|
$html
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testWhitelistIsConfigurable()
|
|
||||||
{
|
|
||||||
// Allow new whitelisted attribute
|
|
||||||
Config::modify()->merge(EmbedShortcodeProvider::class, 'attribute_whitelist', ['data-some-value']);
|
|
||||||
|
|
||||||
$url = 'https://www.youtube.com/watch?v=dM15HfUYwF0';
|
|
||||||
$html = $this->getShortcodeHtml(
|
|
||||||
$url,
|
|
||||||
$url,
|
|
||||||
<<<EOT
|
|
||||||
<link rel="alternate" type="application/json+oembed" href="https://www.youtube.com/oembed?format=json&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Da2tDOYkFCYo" title="The flying car completes first ever inter-city flight (Official Video)">
|
|
||||||
EOT,
|
|
||||||
<<<EOT
|
|
||||||
{"title":"The flying car completes first ever inter-city flight (Official Video)","author_name":"KleinVision","author_url":"https://www.youtube.com/channel/UCCHAHvcO7KSNmgXVRIJLNkw","type":"video","height":113,"width":200,"version":"1.0","provider_name":"YouTube","provider_url":"https://www.youtube.com/","thumbnail_height":360,"thumbnail_width":480,"thumbnail_url":"https://i.ytimg.com/vi/a2tDOYkFCYo/hqdefault.jpg","html":"\u003ciframe width=\u0022200\u0022 height=\u0022113\u0022 src=\u0022https://www.youtube.com/embed/a2tDOYkFCYo?feature=oembed\u0022 frameborder=\u00220\u0022 allow=\u0022accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\u0022 allowfullscreen\u003e\u003c/iframe\u003e"}
|
|
||||||
EOT,
|
|
||||||
[
|
|
||||||
'url' => $url,
|
|
||||||
'caption' => 'A nice video',
|
|
||||||
'width' => 779,
|
|
||||||
'height' => 437,
|
|
||||||
'data-some-value' => 'my-data',
|
|
||||||
'onmouseover' => 'alert(2)',
|
|
||||||
'style' => 'background-color:red;',
|
|
||||||
],
|
|
||||||
);
|
|
||||||
$this->assertEqualIgnoringWhitespace(
|
|
||||||
<<<EOT
|
|
||||||
<div data-some-value="my-data" style="width:779px;"><iframe width="779" height="437" src="https://www.youtube.com/embed/a2tDOYkFCYo?feature=oembed" frameborder="0" allow="accelerometer;autoplay;clipboard-write;encrypted-media;gyroscope;picture-in-picture" allowfullscreen></iframe><p class="caption">A nice video</p></div>
|
|
||||||
EOT,
|
|
||||||
$html
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user