diff --git a/core/model/fieldtypes/HTMLText.php b/core/model/fieldtypes/HTMLText.php index 8642f677e..2d1901e14 100755 --- a/core/model/fieldtypes/HTMLText.php +++ b/core/model/fieldtypes/HTMLText.php @@ -77,9 +77,13 @@ class HTMLText extends Text { * that does very badly on broken HTML*/ if (!$str) { /* See if we can pull a paragraph out*/ - if (preg_match('{
]*)?>(.*[A-Za-z]+.*)
}', $this->value, $matches)) $str = $matches[2]; + + // Strip out any images in case there's one at the beginning. Not doing this will return a blank paragraph + $str = preg_replace('{^\s*(<.+?>)*]*>}', '', $this->value); + if (preg_match('{]*)?>(.*[A-Za-z]+.*)
}', $str, $matches)) $str = $matches[2]; + /* If _that_ failed, just use the whole text */ - else $str = $this->value; + if (!$str) $str = $this->value; /* Now pull out all the html-alike stuff */ $str = preg_replace('{?[a-zA-Z]+[^<>]*>}', '', $str); /* Take out anything that is obviously a tag */ diff --git a/tests/fieldtypes/HTMLTextTest.php b/tests/fieldtypes/HTMLTextTest.php index 7f57f446f..207e19660 100644 --- a/tests/fieldtypes/HTMLTextTest.php +++ b/tests/fieldtypes/HTMLTextTest.php @@ -27,7 +27,10 @@ class HTMLTextTest extends SapphireTest { 'Should take paragraph
' => 'Should take paragraph', 'Should strip tags, but leave text
' => 'Should strip tags, but leave text', 'Unclosed tags
should not phase it
Second paragraph
should not cause errors or appear in output
' => 'Second paragraph' + 'Second paragraph
should not cause errors or appear in output
' => 'Second paragraph', + 'Second paragraph
should not cause errors or appear in output
' => 'Second paragraph', + 'Second paragraph
should not cause errors or appear in output
' => 'Second paragraph', + 'example text words hello
' => 'example text words hello', ); foreach($cases as $originalValue => $expectedValue) {