From e18807baccea84b42adfbdd4f1764c6449968f5f Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Fri, 10 Feb 2023 15:46:34 +0000 Subject: [PATCH 1/4] html purifier tweaks for video embed in ckeditor 5 --- src/helpers/HtmlPurifier.php | 4 ++++ src/htmlpurifier/VideoEmbedUrlDef.php | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/htmlpurifier/VideoEmbedUrlDef.php diff --git a/src/helpers/HtmlPurifier.php b/src/helpers/HtmlPurifier.php index aec5dcfa5e2..4f9c259efe1 100644 --- a/src/helpers/HtmlPurifier.php +++ b/src/helpers/HtmlPurifier.php @@ -7,6 +7,7 @@ namespace craft\helpers; +use craft\htmlpurifier\VideoEmbedUrlDef; use HTMLPurifier_Config; /** @@ -71,6 +72,9 @@ public static function configure($config) // https://github.com/ezyang/htmlpurifier/issues/152#issuecomment-414192516 $def->addAttribute('a', 'download', 'URI'); + + $def->addElement('video-embed', 'Block', 'Inline', 'Common'); + $def->addAttribute('video-embed', 'url', new VideoEmbedUrlDef()); } } } diff --git a/src/htmlpurifier/VideoEmbedUrlDef.php b/src/htmlpurifier/VideoEmbedUrlDef.php new file mode 100644 index 00000000000..4eab15160b7 --- /dev/null +++ b/src/htmlpurifier/VideoEmbedUrlDef.php @@ -0,0 +1,18 @@ +get('URI.SafeIframeRegexp'); + if ($regexp !== null) { + if (!preg_match($regexp, $uri)) { + return false; + } + } + + return parent::validate($uri, $config, $context); + } +} From 210ee7e722f099858ebb66ba7b78118f8f732e18 Mon Sep 17 00:00:00 2001 From: Iwona Just Date: Tue, 14 Feb 2023 14:54:06 +0000 Subject: [PATCH 2/4] use oembed --- src/helpers/HtmlPurifier.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/helpers/HtmlPurifier.php b/src/helpers/HtmlPurifier.php index 4f9c259efe1..436072f2f66 100644 --- a/src/helpers/HtmlPurifier.php +++ b/src/helpers/HtmlPurifier.php @@ -73,8 +73,8 @@ public static function configure($config) // https://github.com/ezyang/htmlpurifier/issues/152#issuecomment-414192516 $def->addAttribute('a', 'download', 'URI'); - $def->addElement('video-embed', 'Block', 'Inline', 'Common'); - $def->addAttribute('video-embed', 'url', new VideoEmbedUrlDef()); + $def->addElement('oembed', 'Block', 'Inline', 'Common'); + $def->addAttribute('oembed', 'url', new VideoEmbedUrlDef()); } } } From e52fadbd2fb9bd6a22119d6edd8d149ad6d632b9 Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 14 Feb 2023 10:20:28 -0800 Subject: [PATCH 3/4] Release note --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb1c92cb8cf..eea21574be0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Unreleased +- HTML Purifier now allows `oembed` tags. ([ckeditor#59](https://github.com/craftcms/ckeditor/issues/59)) - Fixed a bug where entries that aren’t propagated to the primary site weren’t showing revision notes. ([#12641](https://github.com/craftcms/cms/issues/12641)) - Fixed a bug where HTML tags weren’t getting stripped from auto-generated Handle and URI Format setting values. - Fixed a JavaScript error that could occur if an object with `null `values was passed to `Craft.compare()`. From df5c29a49c30b5ae0a744c926c627babcdfdffff Mon Sep 17 00:00:00 2001 From: brandonkelly Date: Tue, 14 Feb 2023 10:25:55 -0800 Subject: [PATCH 4/4] Docblocks + changelog tweak --- CHANGELOG.md | 1 + src/htmlpurifier/VideoEmbedUrlDef.php | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eea21574be0..6e5146d7283 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Unreleased - HTML Purifier now allows `oembed` tags. ([ckeditor#59](https://github.com/craftcms/ckeditor/issues/59)) +- Added `craft\htmlpurifier\VideoEmbedUrlDef`. - Fixed a bug where entries that aren’t propagated to the primary site weren’t showing revision notes. ([#12641](https://github.com/craftcms/cms/issues/12641)) - Fixed a bug where HTML tags weren’t getting stripped from auto-generated Handle and URI Format setting values. - Fixed a JavaScript error that could occur if an object with `null `values was passed to `Craft.compare()`. diff --git a/src/htmlpurifier/VideoEmbedUrlDef.php b/src/htmlpurifier/VideoEmbedUrlDef.php index 4eab15160b7..2a8fb4ff8f9 100644 --- a/src/htmlpurifier/VideoEmbedUrlDef.php +++ b/src/htmlpurifier/VideoEmbedUrlDef.php @@ -1,8 +1,21 @@ + * @since 3.7.66 + */ +class VideoEmbedUrlDef extends HTMLPurifier_AttrDef_URI { public function validate($uri, $config, $context) {