mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
Merge pull request #8729 from emteknetnz/bugfix/htmlvalue-getcontent
Ensure document is not falsey before attempting to clone it
This commit is contained in:
commit
a589bcb092
@ -35,7 +35,11 @@ abstract class HTMLValue extends ViewableData
|
|||||||
*/
|
*/
|
||||||
public function getContent()
|
public function getContent()
|
||||||
{
|
{
|
||||||
$doc = clone $this->getDocument();
|
$document = $this->getDocument();
|
||||||
|
if (!$document) {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
$doc = clone $document;
|
||||||
$xp = new DOMXPath($doc);
|
$xp = new DOMXPath($doc);
|
||||||
|
|
||||||
// If there's no body, the content is empty string
|
// If there's no body, the content is empty string
|
||||||
|
@ -80,4 +80,19 @@ class HTML4ValueTest extends SapphireTest
|
|||||||
$value->setContent('<a href="""></a>');
|
$value->setContent('<a href="""></a>');
|
||||||
$this->assertEquals('<a href="""></a>', $value->getContent(), "'\"' character is escaped");
|
$this->assertEquals('<a href="""></a>', $value->getContent(), "'\"' character is escaped");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testGetContent()
|
||||||
|
{
|
||||||
|
$value = new HTML4Value();
|
||||||
|
|
||||||
|
$value->setContent('<p>This is valid</p>');
|
||||||
|
$this->assertEquals('<p>This is valid</p>', $value->getContent(), "Valid content is returned");
|
||||||
|
|
||||||
|
$value->setContent('<p?< This is not really valid but it will get parsed into something valid');
|
||||||
|
// can sometimes get a this state where HTMLValue->valid is false
|
||||||
|
// for instance if a content editor saves something really weird in a LiteralField
|
||||||
|
// we can manually get to this state via ->setInvalid()
|
||||||
|
$value->setInvalid();
|
||||||
|
$this->assertEquals('', $value->getContent(), "Blank string is returned when invalid");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user