Browse Source

2002-10-09 Gonzalo Paniagua Javier <[email protected]>

	* ConfigHelper.cs:
	* NameValueFileSectionHandler.cs: check that Attributes is not null.

svn path=/trunk/mcs/; revision=8122
Gonzalo Paniagua Javier 23 years ago
parent
commit
27d89dfd8a

+ 5 - 0
mcs/class/System/System.Configuration/ChangeLog

@@ -1,3 +1,8 @@
+2002-10-09  Gonzalo Paniagua Javier <[email protected]>
+
+	* ConfigHelper.cs:
+	* NameValueFileSectionHandler.cs: check that Attributes is not null.
+
 2002-10-09  Miguel de Icaza  <[email protected]>
 
 	* NameValueFileSectionHandler.cs: For now if a section is not

+ 12 - 5
mcs/class/System/System.Configuration/ConfigHelper.cs

@@ -115,12 +115,13 @@ namespace System.Configuration
 							    string nameAtt,
 							    string valueAtt)
 		{
-			if (region.Attributes.Count != 0)
+			if (region.Attributes != null && region.Attributes.Count != 0)
 				throw new ConfigurationException ("Unknown attribute", region);
 
 			XmlNode keyNode;
 			XmlNode valueNode;
-			foreach (XmlNode node in region.ChildNodes) {
+			XmlNodeList childs = region.ChildNodes;
+			foreach (XmlNode node in childs) {
 				XmlNodeType ntype = node.NodeType;
 				if (ntype == XmlNodeType.Whitespace || ntype == XmlNodeType.Comment)
 					continue;
@@ -130,12 +131,15 @@ namespace System.Configuration
 					
 				string nodeName = node.Name;
 				if (nodeName == "clear") {
-					if (node.Attributes.Count != 0)
+					if (node.Attributes != null && node.Attributes.Count != 0)
 						throw new ConfigurationException ("Unknown attribute", node);
 
 					result.Clear ();
 				} else if (nodeName == "remove") {
-					keyNode = node.Attributes.RemoveNamedItem (nameAtt);
+					keyNode = null;
+					if (node.Attributes != null)
+						keyNode = node.Attributes.RemoveNamedItem (nameAtt);
+
 					if (keyNode == null)
 						throw new ConfigurationException ("Required attribute not found",
 										  node);
@@ -148,7 +152,10 @@ namespace System.Configuration
 					
 					result.Remove (keyNode.Value);
 				} else if (nodeName == "add") {
-					keyNode = node.Attributes.RemoveNamedItem (nameAtt);
+					keyNode = null;
+					if (node.Attributes != null)
+						keyNode = node.Attributes.RemoveNamedItem (nameAtt);
+
 					if (keyNode == null)
 						throw new ConfigurationException ("Required attribute not found",
 										  node);

+ 5 - 5
mcs/class/System/System.Configuration/NameValueFileSectionHandler.cs

@@ -18,17 +18,17 @@ namespace System.Configuration
 	{
 		public object Create (object parent, object configContext, XmlNode section)
 		{
-			if (section.Attributes == null)
-				return null;
-			
-			XmlNode file = section.Attributes.RemoveNamedItem ("file");
+			XmlNode file = null;
+			if (section.Attributes != null)
+				file = section.Attributes.RemoveNamedItem ("file");
+
 			NameValueCollection pairs = ConfigHelper.GetNameValueCollection (
 									parent as NameValueCollection,
 									section,
 									"key",
 									"value");
 
-			if (pairs == null && file.Value == String.Empty) {
+			if (file != null && file.Value == String.Empty) {
 				if (!(file is IConfigXmlNode))
 					return null;