Commit 7d37585e authored by catch's avatar catch

Issue #2511306 by ElusiveMind, JeroenT, leolando.tan: Error: Call to a member...

Issue #2511306 by ElusiveMind, JeroenT, leolando.tan: Error: Call to a member function getElementsByTagName() in filter.module
parent e54454a3
...@@ -292,14 +292,16 @@ public static function serialize(\DOMDocument $document) { ...@@ -292,14 +292,16 @@ public static function serialize(\DOMDocument $document) {
$body_node = $document->getElementsByTagName('body')->item(0); $body_node = $document->getElementsByTagName('body')->item(0);
$html = ''; $html = '';
foreach ($body_node->getElementsByTagName('script') as $node) { if ($body_node !== NULL) {
static::escapeCdataElement($node); foreach ($body_node->getElementsByTagName('script') as $node) {
} static::escapeCdataElement($node);
foreach ($body_node->getElementsByTagName('style') as $node) { }
static::escapeCdataElement($node, '/*', '*/'); foreach ($body_node->getElementsByTagName('style') as $node) {
} static::escapeCdataElement($node, '/*', '*/');
foreach ($body_node->childNodes as $node) { }
$html .= $document->saveXML($node); foreach ($body_node->childNodes as $node) {
$html .= $document->saveXML($node);
}
} }
return $html; return $html;
} }
......
...@@ -312,4 +312,17 @@ public function testDecodeEntitiesAndEscape() { ...@@ -312,4 +312,17 @@ public function testDecodeEntitiesAndEscape() {
$this->assertSame('<em>répété</em>', $escaped); $this->assertSame('<em>répété</em>', $escaped);
} }
} /**
* Tests Html::serialize().
*
* Resolves an issue by where an empty DOMDocument object sent to serialization would
* cause errors in getElementsByTagName() in the serialization function.
*
* @covers ::serialize
*/
public function testSerialize() {
$document = new \DOMDocument();
$result = Html::serialize($document);
$this->assertSame('', $result);
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment