diff --git a/common/functions.php b/common/functions.php
index aede0bc53..046586c75 100644
--- a/common/functions.php
+++ b/common/functions.php
@@ -606,15 +606,18 @@ function is_html_content($str)
{
$str = preg_replace('![\r\n]+!', "\n", utf8_trim(utf8_clean($str)));
$line_count = substr_count($str, "\n") + 1;
- $tag_count = preg_match_all('!(?:^<(?:p|div)(?:>|\s*[a-z])|<(?:/p|/div|br\s?/?)>$)!im', $str);
- if ($tag_count > 4 || ($tag_count > 0 && $tag_count >= $line_count - 1))
+ $p_tag_count = preg_match_all('!(?:^<(?:p|div|h[1-6])(?:>|\s*[a-z])|(?:p|div|h[1-6])>$)!im', $str);
+ if ($p_tag_count > 4 || ($p_tag_count > 0 && $p_tag_count >= $line_count * 2))
{
return true;
}
- else
+ $br_tag_count = preg_match_all('!
$!im', $str);
+ if ($br_tag_count > 4 || ($br_tag_count > 0 && $br_tag_count >= $line_count - 1))
{
- return false;
+ return true;
}
+
+ return false;
}
/**
diff --git a/tests/unit/functions/FunctionsTest.php b/tests/unit/functions/FunctionsTest.php
index a15471707..8c5755435 100644
--- a/tests/unit/functions/FunctionsTest.php
+++ b/tests/unit/functions/FunctionsTest.php
@@ -178,6 +178,8 @@ class FunctionsTest extends \Codeception\TestCase\Test
$this->assertTrue(is_html_content("
tag.")); $this->assertFalse(is_html_content("This is multiline content.\n
tag is here.\nOther lines are here, too.
\nMost lines don't have any tags."));
+ $this->assertFalse(is_html_content("
tag is unbalanced here.\nAnother line!
\nAnd a dangling line..."));
+ $this->assertFalse(is_html_content("Looks like a broken editor
\nthat produced\nthis kind of\nstring!"));
}
public function testIsEmptyHTMLContent()