Просмотр исходного кода

[Xml] Fix GetAttribute to handle null namespaces properly, add unit test.

Andreia Gaita 15 лет назад
Родитель
Сommit
ef80c566af

+ 1 - 0
mcs/class/System.XML/System.Xml/XmlTextReader.cs

@@ -424,6 +424,7 @@ namespace System.Xml
 
 		private int GetIndexOfQualifiedAttribute (string localName, string namespaceURI)
 		{
+			namespaceURI = namespaceURI ?? String.Empty;
 			for (int i = 0; i < attributeCount; i++) {
 				XmlAttributeTokenInfo ti = attributeTokens [i];
 				if (ti.LocalName == localName && ti.NamespaceURI == namespaceURI)

+ 10 - 0
mcs/class/System.XML/Test/System.Xml/XmlTextReaderTests.cs

@@ -1348,5 +1348,15 @@ namespace MonoTests.System.Xml
 			XmlDocument doc = new XmlDocument ();
 			doc.LoadXml ("<root xml:base='' />");
 		}
+
+		[Test]
+		public void GetAttribute ()
+		{
+			StringReader sr = new StringReader("<rootElement myAttribute=\"the value\"></rootElement>");
+			using (XmlReader reader = XmlReader.Create(sr)) {
+				reader.Read ();
+				Assert.AreEqual (reader.GetAttribute("myAttribute", null), "the value", "#1");
+			}
+		}
 	}
 }