Skip to content

Commit 80b3504

Browse files
fix HTML filter issue when the text contains malformed HTML tags (#27)
1 parent a358650 commit 80b3504

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/Source/Filter/HtmlFilter.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public function filter(string $string): string
120120
case '>' === $char:
121121
if ($this->isIgnoredTag($tagName)) {
122122
$ignoreTagContent = true;
123-
} elseif ('/' === $tagName[0]) {
123+
} elseif ($tagName === null || '/' === $tagName[0]) {
124124
$ignoreTagContent = false; // Restore to default state.
125125
}
126126
$context = self::CTX_TAG_CONTENT;
@@ -258,6 +258,10 @@ function ($match) {
258258
*/
259259
private function isIgnoredTag(?string $name): bool
260260
{
261+
if ($name === null) {
262+
return false;
263+
}
264+
261265
foreach (self::$ignoreTags as $tag) {
262266
if (strcasecmp($tag, $name) === 0) {
263267
return true;

tests/Unit/Source/Filter/HtmlFilterTest.php

+8
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,12 @@ public function testMalformedAttribute(): void
9090
$text = ' test ';
9191
static::assertEquals($text, $filter->filter($html));
9292
}
93+
94+
public function testMalformedTags(): void
95+
{
96+
$filter = new HtmlFilter();
97+
$html = "foo/>bar<br><br/>";
98+
$text = "foo/ bar ";
99+
static::assertEquals($text, $filter->filter($html));
100+
}
93101
}

0 commit comments

Comments
 (0)