Skip to content
Permalink
Browse files

MDL-48546 filters: Split on all tags for multimedia filter check.

  • Loading branch information...
zbdd authored and stronk7 committed Jan 7, 2015
1 parent 505f675 commit 531492a32cf77f90bc48c4868a5f71dd7040049f
Showing with 14 additions and 1 deletion.
  1. +1 −1 filter/mediaplugin/filter.php
  2. +13 −0 filter/mediaplugin/tests/filter_test.php
@@ -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;
@@ -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>',
@@ -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 531492a

Please sign in to comment.
You can’t perform that action at this time.