From 118a03cf1c1825f6f11af237de810264411498a1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Andreas=20=C3=85kre=20Solberg?= <andreas.solberg@uninett.no>
Date: Sat, 29 Nov 2008 13:30:14 +0000
Subject: [PATCH] fix bug when comment nodes where inside an entitydescriptor
 did fail

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@1036 44740490-163a-0410-bde0-09ae8108e29a
---
 lib/SimpleSAML/Metadata/SAMLParser.php | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/lib/SimpleSAML/Metadata/SAMLParser.php b/lib/SimpleSAML/Metadata/SAMLParser.php
index fdd8fd5b3..bd896f8ee 100644
--- a/lib/SimpleSAML/Metadata/SAMLParser.php
+++ b/lib/SimpleSAML/Metadata/SAMLParser.php
@@ -163,10 +163,8 @@ class SimpleSAML_Metadata_SAMLParser {
 		for($i = 0; $i < $entityElement->childNodes->length; $i++) {
 			$child = $entityElement->childNodes->item($i);
 
-			/* Skip text nodes. */
-			if($child instanceof DOMText) {
-				continue;
-			}
+			// Unless the child is a DOMElement, skip.
+			if ( !($child instanceof DOMelement) ) continue;
 
 			if(SimpleSAML_Utilities::isDOMElementOfType($child, 'Signature', '@ds') === TRUE) {
 				$this->processSignature($child);
@@ -262,12 +260,15 @@ class SimpleSAML_Metadata_SAMLParser {
 	 */
 	public static function parseDescriptorsFile($file) {
 
+		if ($file === NULL) throw new Exception('Cannot open file NULL. File name not specified.');
+
 		$doc = new DOMDocument();
 
 		$res = $doc->load($file);
 		if($res !== TRUE) {
 			throw new Exception('Failed to read XML from file: ' . $file);
 		}
+		if ($doc->documentElement === NULL) throw new Exception('Opened file is not an XML document: ' . $file);
 
 		return self::parseDescriptorsElement($doc->documentElement);
 	}
@@ -309,7 +310,7 @@ class SimpleSAML_Metadata_SAMLParser {
 		}
 
 		assert('$element instanceof DOMElement');
-
+		
 		$entitiesValidator = NULL;
 
 		if(SimpleSAML_Utilities::isDOMElementOfType($element, 'EntityDescriptor', '@md') === TRUE) {
-- 
GitLab