Skip to content
Snippets Groups Projects
Commit 63791019 authored by David Rothstein's avatar David Rothstein
Browse files

Issue #2511306 by ElusiveMind, JeroenT, leolando.tan, cilefen, charginghawk:...

Issue #2511306 by ElusiveMind, JeroenT, leolando.tan, cilefen, charginghawk: Error: Call to a member function getElementsByTagName() in filter.module when filter_dom_serialize() is passed an empty document.
parent f7548361
No related branches found
No related tags found
No related merge requests found
......@@ -1119,18 +1119,23 @@ function filter_dom_serialize($dom_document) {
$body_node = $dom_document->getElementsByTagName('body')->item(0);
$body_content = '';
foreach ($body_node->getElementsByTagName('script') as $node) {
filter_dom_serialize_escape_cdata_element($dom_document, $node);
}
if ($body_node !== NULL) {
foreach ($body_node->getElementsByTagName('script') as $node) {
filter_dom_serialize_escape_cdata_element($dom_document, $node);
}
foreach ($body_node->getElementsByTagName('style') as $node) {
filter_dom_serialize_escape_cdata_element($dom_document, $node, '/*', '*/');
}
foreach ($body_node->getElementsByTagName('style') as $node) {
filter_dom_serialize_escape_cdata_element($dom_document, $node, '/*', '*/');
}
foreach ($body_node->childNodes as $child_node) {
$body_content .= $dom_document->saveXML($child_node);
foreach ($body_node->childNodes as $child_node) {
$body_content .= $dom_document->saveXML($child_node);
}
return preg_replace('|<([^> ]*)/>|i', '<$1 />', $body_content);
}
else {
return $body_content;
}
return preg_replace('|<([^> ]*)/>|i', '<$1 />', $body_content);
}
/**
......
......@@ -1983,3 +1983,26 @@ class FilterSettingsTestCase extends DrupalWebTestCase {
}
}
}
/**
* Tests DOMDocument serialization.
*/
class FilterDOMSerializeTestCase extends DrupalWebTestCase {
public static function getInfo() {
return array(
'name' => 'Serialization',
'description' => 'Test serialization of DOMDocument objects.',
'group' => 'Filter',
);
}
/**
* Tests empty DOMDocument object.
*/
function testFilterEmptyDOMSerialization() {
$document = new DOMDocument();
$result = filter_dom_serialize($document);
$this->assertEqual('', $result);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment