Skip to content

Commit

Permalink
MDL-48546 filters: Split on all tags for multimedia filter check.
Browse files Browse the repository at this point in the history
  • Loading branch information
zbdd authored and stronk7 committed Jan 7, 2015
1 parent 2d90c64 commit 63ed941
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion filter/mediaplugin/filter.php
Expand Up @@ -69,7 +69,7 @@ public function filter($text, array $options = array()) {
$this->trusted = !empty($options['noclean']) or !empty($CFG->allowobjectembed);

// Looking for tags.
$matches = preg_split('/(<a\s[^>]*>)/i', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
$matches = preg_split('/(<[^>]*>)/i', $text, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);

if (!$matches) {
return $text;
Expand Down
13 changes: 13 additions & 0 deletions filter/mediaplugin/tests/filter_test.php
Expand Up @@ -100,6 +100,15 @@ function test_filter_mediaplugin_link() {
$insertpoint = strrpos($longurl, 'http://');
$longurl = substr_replace($longurl, 'http://pushover4096chars', $insertpoint, 0);

$originalurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;">' .
'<a href="https://www.youtube.com/watch?v=uUhWl9Lm3OM">Valid link</a></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">';
$paddedurl = str_pad($originalurl, 6000, 'z');
$validpaddedurl = '<p>Some text.</p><pre style="color: rgb(0, 0, 0); line-height: normal;"><span class="mediaplugin mediaplugin_youtube">
<iframe title="Valid link" width="400" height="300"
src="https://www.youtube.com/embed/uUhWl9Lm3OM?rel=0&wmode=transparent" frameborder="0" allowfullscreen="1"></iframe>
</span></pre><pre style="color: rgb(0, 0, 0); line-height: normal;">';
$validpaddedurl = str_pad($validpaddedurl, 6000 + (strlen($validpaddedurl) - strlen($originalurl)), 'z');

$invalidtexts = array(
'<a class="_blanktarget">href="http://moodle.org/testfile/test.mp3"</a>',
'<a>test test</a>',
Expand Down Expand Up @@ -132,5 +141,9 @@ function test_filter_mediaplugin_link() {
$filter = $filterplugin->filter($precededlongurl);
$this->assertEquals(1, substr_count($filter, 'M.util.add_audio_player'));
$this->assertContains($longurl, $filter);

// Testing for cases where: to be filtered content has 6+ text afterwards.
$filter = $filterplugin->filter($paddedurl);
$this->assertEquals($validpaddedurl, $filter, $msg);
}
}

0 comments on commit 63ed941

Please sign in to comment.