Skip to content

Commit 6a2bb23

Browse files
[2.x] Fix case insensitvity and recursiveness in stripImages and stripIframes (#73)
Co-authored-by: Richard Fath <richard67@users.noreply.github.com>
1 parent 3539f6d commit 6a2bb23

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

Tests/OutputFilterTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,18 @@ public function testStripImages()
215215
$this->object->stripImages('Hello <img src="wave.jpg"> I am waving at you.'),
216216
'Should remove img tags'
217217
);
218+
219+
$this->assertEquals(
220+
'Hello I am waving at you.',
221+
$this->object->stripImages('Hello <IMG src="wave.jpg"> I am waving at you.'),
222+
'Should remove uppercase img tags'
223+
);
224+
225+
$this->assertEquals(
226+
'Hello I am waving at you.',
227+
$this->object->stripImages('Hello <<img>IMg src="wave.jpg"> I am waving at you.'),
228+
'Should remove nested tags'
229+
);
218230
}
219231

220232
/**
@@ -229,5 +241,19 @@ public function testStripIframes()
229241
),
230242
'Should remove iFrame tags'
231243
);
244+
245+
$this->assertEquals(
246+
'Hello I am waving at you.',
247+
$this->object->stripIframes('Hello <IFrame src="http://player.vimeo.com/video/37576499" width="500"' .
248+
' height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> I am waving at you.'),
249+
'Should remove uppercase iFrame tags'
250+
);
251+
252+
$this->assertEquals(
253+
'Hello I am waving at you.',
254+
$this->object->stripIframes('Hello <<iframe>iframe src="http://player.vimeo.com/video/37576499" width="500"' .
255+
' height="281" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe> I am waving at you.'),
256+
'Should remove nested iFrame tags'
257+
);
232258
}
233259
}

src/OutputFilter.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,12 @@ public static function setLanguage(Language $language): void
275275
*/
276276
public static function stripImages($string)
277277
{
278-
return preg_replace('#(<[/]?img.*>)#U', '', $string);
278+
while (preg_match('#(<[/]?img.*>)#Ui', $string))
279+
{
280+
$string = preg_replace('#(<[/]?img.*>)#Ui', '', $string);
281+
}
282+
283+
return $string;
279284
}
280285

281286
/**
@@ -289,6 +294,11 @@ public static function stripImages($string)
289294
*/
290295
public static function stripIframes($string)
291296
{
292-
return preg_replace('#(<[/]?iframe.*>)#U', '', $string);
297+
while (preg_match('#(<[/]?iframe.*>)#Ui', $string))
298+
{
299+
$string = preg_replace('#(<[/]?iframe.*>)#Ui', '', $string);
300+
}
301+
302+
return $string;
293303
}
294304
}

0 commit comments

Comments
 (0)