Skip to content

Commit

Permalink
fix HTML filter issue when the text contains malformed HTML tags (mek…
Browse files Browse the repository at this point in the history
  • Loading branch information
olivierpontier committed Aug 20, 2020
1 parent a358650 commit 80b3504
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Source/Filter/HtmlFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function filter(string $string): string
case '>' === $char:
if ($this->isIgnoredTag($tagName)) {
$ignoreTagContent = true;
} elseif ('/' === $tagName[0]) {
} elseif ($tagName === null || '/' === $tagName[0]) {
$ignoreTagContent = false; // Restore to default state.
}
$context = self::CTX_TAG_CONTENT;
Expand Down Expand Up @@ -258,6 +258,10 @@ function ($match) {
*/
private function isIgnoredTag(?string $name): bool
{
if ($name === null) {
return false;
}

foreach (self::$ignoreTags as $tag) {
if (strcasecmp($tag, $name) === 0) {
return true;
Expand Down
8 changes: 8 additions & 0 deletions tests/Unit/Source/Filter/HtmlFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@ public function testMalformedAttribute(): void
$text = ' test ';
static::assertEquals($text, $filter->filter($html));
}

public function testMalformedTags(): void
{
$filter = new HtmlFilter();
$html = "foo/>bar<br><br/>";
$text = "foo/ bar ";
static::assertEquals($text, $filter->filter($html));
}
}

0 comments on commit 80b3504

Please sign in to comment.