Skip to content

Commit

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

Co-authored-by: Richard Fath <[email protected]>
  • Loading branch information
SniperSister and richard67 authored Aug 20, 2024
1 parent 8da26e8 commit 156c03c
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 @@ -227,6 +227,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 @@ -244,5 +256,19 @@ public function testStripIframes()
' height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> I am waving at you.'),
'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 @@ -197,7 +197,12 @@ public static function cleanText(&$text)
*/
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 @@ -211,6 +216,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 156c03c

Please sign in to comment.