Skip to content

Commit

Permalink
[2.x] Fix case insensitvity and recursiveness in stripImages and stri…
Browse files Browse the repository at this point in the history
…pIframes (#73)

Co-authored-by: Richard Fath <[email protected]>
  • Loading branch information
SniperSister and richard67 authored Aug 20, 2024
1 parent 3539f6d commit 6a2bb23
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
26 changes: 26 additions & 0 deletions Tests/OutputFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ public function testStripImages()
$this->object->stripImages('Hello <img src="wave.jpg"> I am waving at you.'),
'Should remove img tags'
);

$this->assertEquals(
'Hello I am waving at you.',
$this->object->stripImages('Hello <IMG src="wave.jpg"> I am waving at you.'),
'Should remove uppercase img tags'
);

$this->assertEquals(
'Hello I am waving at you.',
$this->object->stripImages('Hello <<img>IMg src="wave.jpg"> I am waving at you.'),
'Should remove nested tags'
);
}

/**
Expand All @@ -229,5 +241,19 @@ public function testStripIframes()
),
'Should remove iFrame tags'
);

$this->assertEquals(
'Hello I am waving at you.',
$this->object->stripIframes('Hello <IFrame src="http://player.vimeo.com/video/37576499" width="500"' .
' height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> I am waving at you.'),
'Should remove uppercase iFrame tags'
);

$this->assertEquals(
'Hello I am waving at you.',
$this->object->stripIframes('Hello <<iframe>iframe src="http://player.vimeo.com/video/37576499" width="500"' .
' height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> I am waving at you.'),
'Should remove nested iFrame tags'
);
}
}
14 changes: 12 additions & 2 deletions src/OutputFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,12 @@ public static function setLanguage(Language $language): void
*/
public static function stripImages($string)
{
return preg_replace('#(<[/]?img.*>)#U', '', $string);
while (preg_match('#(<[/]?img.*>)#Ui', $string))
{
$string = preg_replace('#(<[/]?img.*>)#Ui', '', $string);
}

return $string;
}

/**
Expand All @@ -289,6 +294,11 @@ public static function stripImages($string)
*/
public static function stripIframes($string)
{
return preg_replace('#(<[/]?iframe.*>)#U', '', $string);
while (preg_match('#(<[/]?iframe.*>)#Ui', $string))
{
$string = preg_replace('#(<[/]?iframe.*>)#Ui', '', $string);
}

return $string;
}
}

0 comments on commit 6a2bb23

Please sign in to comment.