From bd7702ca83a56161d60ec06c255309d6e845cc84 Mon Sep 17 00:00:00 2001 From: Julien Boulen Date: Mon, 15 May 2023 17:21:19 +0200 Subject: [PATCH] MDL-78259 weblib: purify audio/video tags as inline elements --- lib/tests/htmlpurifier_test.php | 6 ++++++ lib/weblib.php | 6 +++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/tests/htmlpurifier_test.php b/lib/tests/htmlpurifier_test.php index dc9137a5f8c..c047044f031 100644 --- a/lib/tests/htmlpurifier_test.php +++ b/lib/tests/htmlpurifier_test.php @@ -426,6 +426,12 @@ class htmlpurifier_test extends \basic_testcase { '', '
' + ]) + $generatetestcases('Video inside an inline tag', $videoattrs + ['src="http://example.com/prettygood.mp4'], [ + '', + '
' + ]) + $generatetestcases('Video inside a block tag', $videoattrs + ['src="http://example.com/prettygood.mp4'], [ + '

', + '

' ]) + $generatetestcases('Source tag without video or audio', $videoattrs, [ 'some text the end', '
some text the end
' diff --git a/lib/weblib.php b/lib/weblib.php index 89a4b6e3da2..29041dffb03 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -1888,7 +1888,7 @@ function purify_html($text, $options = array()) { $config = HTMLPurifier_Config::createDefault(); $config->set('HTML.DefinitionID', 'moodlehtml'); - $config->set('HTML.DefinitionRev', 6); + $config->set('HTML.DefinitionRev', 7); $config->set('Cache.SerializerPath', $cachedir); $config->set('Cache.SerializerPermissions', $CFG->directorypermissions); $config->set('Core.NormalizeNewlines', false); @@ -1930,7 +1930,7 @@ function purify_html($text, $options = array()) { // Media elements. // https://html.spec.whatwg.org/#the-video-element - $def->addElement('video', 'Block', 'Optional: #PCDATA | Flow | source | track', 'Common', [ + $def->addElement('video', 'Inline', 'Optional: #PCDATA | Flow | source | track', 'Common', [ 'src' => 'URI', 'crossorigin' => 'Enum#anonymous,use-credentials', 'poster' => 'URI', @@ -1944,7 +1944,7 @@ function purify_html($text, $options = array()) { 'height' => 'Length', ]); // https://html.spec.whatwg.org/#the-audio-element - $def->addElement('audio', 'Block', 'Optional: #PCDATA | Flow | source | track', 'Common', [ + $def->addElement('audio', 'Inline', 'Optional: #PCDATA | Flow | source | track', 'Common', [ 'src' => 'URI', 'crossorigin' => 'Enum#anonymous,use-credentials', 'preload' => 'Enum#auto,metadata,none',