Skip to content

Commit

Permalink
Merge branch 'wip-MDL-55581-30' of git://github.com/marinaglancy/mood…
Browse files Browse the repository at this point in the history
…le into MOODLE_30_STABLE
  • Loading branch information
David Monllao committed Aug 29, 2016
2 parents 092fecd + 4496863 commit 12ed025
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 26 deletions.
83 changes: 60 additions & 23 deletions lib/tests/htmlpurifier_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public function test_allowed_schemes() {
* @param string $expected expected result
*/
public function test_media_tags($mediatag, $expected) {
$actual = format_text($mediatag, FORMAT_MOODLE, ['filter' => false, 'noclean' => true]);
$actual = format_text($mediatag, FORMAT_MOODLE, ['filter' => false]);
$this->assertEquals($expected, $actual);
}

Expand All @@ -353,8 +353,8 @@ public function media_tags_provider() {
$videoattrs = [
'crossorigin="anonymous"', 'crossorigin="use-credentials"',
'poster="https://upload.wikimedia.org/wikipedia/en/1/14/Space_jam.jpg"',
'preload=""', 'autoplay=""', 'playsinline=""', 'loop=""', 'muted=""',
'controls=""', 'width="420px"', 'height="69px"'
'preload="auto"', 'autoplay=""', 'playsinline=""', 'loop=""', 'muted=""',
'controls=""', 'width="420"', 'height="69"'
];
return $generatetestcases('Plain audio', $audioattrs + ['src="http://example.com/jam.wav"'], [
'<audio %1$s>Looks like you can\'t slam the jams.</audio>',
Expand All @@ -363,7 +363,7 @@ public function media_tags_provider() {
'<audio %1$s><source src="http://example.com/getup.wav">No tasty jams for you.</audio>',
'<div class="text_to_html">' .
'<audio %1$s>' .
'<source src="http://example.com/getup.wav">' .
'<source src="http://example.com/getup.wav" />' .
'No tasty jams for you.' .
'</audio>' .
'</div>'
Expand All @@ -375,60 +375,97 @@ public function media_tags_provider() {
'No tasty jams for you.' .
'</audio>',
'<div class="text_to_html">' .
'<audio %1$s>' .
'<source src="http://example.com/getup.wav" type="audio/wav">' .
'<source src="http://example.com/getup.mp3" type="audio/mpeg">' .
'<source src="http://example.com/getup.ogg" type="audio/ogg">' .
'<audio %1$s>' .
'<source src="http://example.com/getup.wav" type="audio/wav" />' .
'<source src="http://example.com/getup.mp3" type="audio/mpeg" />' .
'<source src="http://example.com/getup.ogg" type="audio/ogg" />' .
'No tasty jams for you.' .
'</audio>' .
'</div>'
]) + $generatetestcases('Audio with sources and tracks', $audioattrs, [
'<audio %1$s>' .
'<source src="http://example.com/getup.wav" type="audio/wav">' .
'<track kind="subtitles" src="http://example.com/subtitles_en.vtt" label="English" srclang="en">' .
'<track kind="subtitles" src="http://example.com/subtitles_es.vtt" label="Espanol" srclang="es">' .
'No tasty jams for you.' .
'</audio>',
'<div class="text_to_html">' .
'<audio %1$s>' .
'<source src="http://example.com/getup.wav" type="audio/wav" />' .
'<track kind="subtitles" src="http://example.com/subtitles_en.vtt" label="English" srclang="en" />' .
'<track kind="subtitles" src="http://example.com/subtitles_es.vtt" label="Espanol" srclang="es" />' .
'No tasty jams for you.' .
'</audio>' .
'</div>'
]) + $generatetestcases('Plain video', $videoattrs + ['src="http://example.com/prettygood.mp4'], [
'<video %1$s>Oh, that\'s pretty bad 😦</video>',
'<div class="text_to_html"><video %1$s>Oh, that\'s pretty bad 😦</video></div>'
]) + $generatetestcases('Video with illegal subtag', $videoattrs + ['src="http://example.com/prettygood.mp4'], [
'<video %1$s><subtag></subtag>Oh, that\'s pretty bad 😦</video>',
'<div class="text_to_html"><video %1$s>Oh, that\'s pretty bad 😦</video></div>'
]) + $generatetestcases('Video with legal subtag', $videoattrs + ['src="http://example.com/prettygood.mp4'], [
'<video %1$s>Did not work <a href="http://example.com/prettygood.mp4">click here to download</a></video>',
'<div class="text_to_html"><video %1$s>Did not work <a href="http://example.com/prettygood.mp4">' .
'click here to download</a></video></div>'
]) + $generatetestcases('Source tag without video or audio', $videoattrs, [
'some text <source src="http://example.com/getup.wav" type="audio/wav"> the end',
'<div class="text_to_html">some text the end</div>'
]) + $generatetestcases('Video with one source', $videoattrs, [
'<video %1$s><source src="http://example.com/prettygood.mp4">Oh, that\'s pretty bad 😦</video>',
'<div class="text_to_html">' .
'<video %1$s>' .
'<source src="http://example.com/prettygood.mp4">' .
'<source src="http://example.com/prettygood.mp4" />' .
'Oh, that\'s pretty bad 😦' .
'</video>' .
'</div>'
]) + $generatetestcases('Video with multiple sources', $videoattrs, [
'<video %1$s>' .
'<source src="http://example.com/prettygood.mp4" type="video/mp4">' .
'<source src="http://example.com/eljefe.mp4" type="video/mp4">' .
'<source src="http://example.com/turnitup.mov type="video/mov"' .
'<source src="http://example.com/turnitup.mov" type="video/mov">' .
'Oh, that\'s pretty bad 😦' .
'</video>',
'<div class="text_to_html">' .
'<video %1$s>' .
'<source src="http://example.com/prettygood.mp4" type="video/mp4">' .
'<source src="http://example.com/eljefe.mp4" type="video/mp4">' .
'<source src="http://example.com/turnitup.mov type="video/mov"' .
'<source src="http://example.com/prettygood.mp4" type="video/mp4" />' .
'<source src="http://example.com/eljefe.mp4" type="video/mp4" />' .
'<source src="http://example.com/turnitup.mov" type="video/mov" />' .
'Oh, that\'s pretty bad 😦' .
'</video>' .
'</div>'
] + [
'Video with invalid crossorigin' => [
'<video src="http://example.com/turnitup.mov type="video/mov crossorigin="can i pls hab?">' .
]) + $generatetestcases('Video with sources and tracks', $audioattrs, [
'<video %1$s>' .
'<source src="http://example.com/getup.wav" type="audio/wav">' .
'<track kind="subtitles" src="http://example.com/subtitles_en.vtt" label="English" srclang="en">' .
'<track kind="subtitles" src="http://example.com/subtitles_es.vtt" label="Espanol" srclang="es">' .
'No tasty jams for you.' .
'</video>',
'<div class="text_to_html">' .
'<video %1$s>' .
'<source src="http://example.com/getup.wav" type="audio/wav" />' .
'<track kind="subtitles" src="http://example.com/subtitles_en.vtt" label="English" srclang="en" />' .
'<track kind="subtitles" src="http://example.com/subtitles_es.vtt" label="Espanol" srclang="es" />' .
'No tasty jams for you.' .
'</video>' .
'</div>'
]) + $generatetestcases('Video with invalid crossorigin', $videoattrs, [
'<video src="http://example.com/turnitup.mov" crossorigin="can i pls hab?">' .
'Oh, that\'s pretty bad 😦' .
'</video>',
'<div class="text_to_html">' .
'<video src="http://example.com/turnitup.mov type="video/mov">' .
'<video src="http://example.com/turnitup.mov">' .
'Oh, that\'s pretty bad 😦' .
'</video>',
'</video>' .
'</div>'
],
'Audio with invalid crossorigin' => [
'<audio src="http://example.com/getup.wav" type="audio/wav" crossorigin="give me. the jams.">' .
]) + $generatetestcases('Audio with invalid crossorigin', $audioattrs, [
'<audio src="http://example.com/getup.wav" crossorigin="give me. the jams.">' .
'nyemnyemnyem' .
'</audio>',
'<div class="text_to_html">' .
'<audio src="http://example.com/getup.wav" type="audio/wav" crossorigin="give me. the jams.">' .
'<audio src="http://example.com/getup.wav">' .
'nyemnyemnyem' .
'</audio>' .
'</div>'
]
]);
}
}
14 changes: 11 additions & 3 deletions lib/weblib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1777,7 +1777,7 @@ function purify_html($text, $options = array()) {

// Media elements.
// https://html.spec.whatwg.org/#the-video-element
$def->addElement('video', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
$def->addElement('video', 'Block', 'Optional: #PCDATA | Flow | source | track', 'Common', [
'src' => 'URI',
'crossorigin' => 'Enum#anonymous,use-credentials',
'poster' => 'URI',
Expand All @@ -1791,7 +1791,7 @@ function purify_html($text, $options = array()) {
'height' => 'Length',
]);
// https://html.spec.whatwg.org/#the-audio-element
$def->addElement('audio', 'Block', 'Optional: (source, Flow) | (Flow, source) | Flow', 'Common', [
$def->addElement('audio', 'Block', 'Optional: #PCDATA | Flow | source | track', 'Common', [
'src' => 'URI',
'crossorigin' => 'Enum#anonymous,use-credentials',
'preload' => 'Enum#auto,metadata,none',
Expand All @@ -1801,10 +1801,18 @@ function purify_html($text, $options = array()) {
'controls' => 'Bool'
]);
// https://html.spec.whatwg.org/#the-source-element
$def->addElement('source', 'Block', 'Flow', 'Common', [
$def->addElement('source', false, 'Empty', null, [
'src' => 'URI',
'type' => 'Text'
]);
// https://html.spec.whatwg.org/#the-track-element
$def->addElement('track', false, 'Empty', null, [
'src' => 'URI',
'kind' => 'Enum#subtitles,captions,descriptions,chapters,metadata',
'srclang' => 'Text',
'label' => 'Text',
'default' => 'Bool',
]);

// Use the built-in Ruby module to add annotation support.
$def->manager->addModule(new HTMLPurifier_HTMLModule_Ruby());
Expand Down

0 comments on commit 12ed025

Please sign in to comment.