Skip to content

Commit

Permalink
Merge pull request #8729 from emteknetnz/bugfix/htmlvalue-getcontent
Browse files Browse the repository at this point in the history
Ensure document is not falsey before attempting to clone it
  • Loading branch information
maxime-rainville authored Jan 28, 2019
2 parents 1b63610 + d285529 commit a589bcb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/View/Parsers/HTMLValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ abstract public function setContent($fragment);
*/
public function getContent()
{
$doc = clone $this->getDocument();
$document = $this->getDocument();
if (!$document) {
return '';
}
$doc = clone $document;
$xp = new DOMXPath($doc);

// If there's no body, the content is empty string
Expand Down
15 changes: 15 additions & 0 deletions tests/php/View/Parsers/HTML4ValueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,19 @@ public function testAttributeEscaping()
$value->setContent('<a href="&quot;"></a>');
$this->assertEquals('<a href="&quot;"></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");
}
}

0 comments on commit a589bcb

Please sign in to comment.