ソースを参照

2005-05-10 Atsushi Enomoto <[email protected]>

	* DTDValidatingReader.cs : since namespace declarations might be
	  resolved differently due to entity handling, it holds its own set
	  of declared namespaces. NamespaceURI and LookupNamespace() use it.

	* XmlValidatingReaderTests.cs : fixed TestPreserveEntityNotOnDotNet()
	  which was regarded as a bug while it was by design.


svn path=/trunk/mcs/; revision=44316
Atsushi Eno 20 年 前
コミット
3e84fc4524

+ 6 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,9 @@
+2005-05-10  Atsushi Enomoto <[email protected]>
+
+	* DTDValidatingReader.cs : since namespace declarations might be
+	  resolved differently due to entity handling, it holds its own set
+	  of declared namespaces. NamespaceURI and LookupNamespace() use it.
+
 2005-05-09  Atsushi Enomoto <[email protected]>
 
 	* XmlReader.cs : added ReadElementContentAsLong().

+ 18 - 5
mcs/class/System.XML/System.Xml/DTDValidatingReader.cs

@@ -69,6 +69,7 @@ namespace Mono.Xml
 			attributeLocalNames = new Hashtable ();
 			attributeNamespaces = new Hashtable ();
 			attributePrefixes = new Hashtable ();
+			nsdecls = new Hashtable ();
 			this.validatingReader = validatingReader;
 			valueBuilder = new StringBuilder ();
 			idList = new ArrayList ();
@@ -104,6 +105,7 @@ namespace Mono.Xml
 		Hashtable attributeLocalNames;
 		Hashtable attributeNamespaces;
 		Hashtable attributePrefixes;
+		Hashtable nsdecls;
 		StringBuilder valueBuilder;
 		ArrayList idList;
 		ArrayList missingIDReferences;
@@ -188,7 +190,8 @@ namespace Mono.Xml
 
 		public override string LookupNamespace (string prefix)
 		{
-			// Does it mean anything with DTD?
+			if (nsdecls.Count > 0 && nsdecls [prefix] != null)
+				return (string) nsdecls [prefix];
 			return reader.LookupNamespace (prefix);
 		}
 
@@ -363,6 +366,7 @@ namespace Mono.Xml
 			attributeValues.Clear ();
 			attributeNamespaces.Clear ();
 			attributePrefixes.Clear ();
+			nsdecls.Clear ();
 			isWhitespace = false;
 			isSignificantWhitespace = false;
 			isText = false;
@@ -522,7 +526,12 @@ namespace Mono.Xml
 					// SetupValidityIgnorantAttributes ();
 					ValidateAttributes (null, false);
 				}
-
+				foreach (string attr in attributes)
+					if (attr == "xmlns" ||
+						String.CompareOrdinal (attr, 0, "xmlns", 0, 5) == 0)
+						nsdecls.Add (
+							attr == "xmlns" ? String.Empty : attributePrefixes [attr],
+							attributeValues [attr]);
 				// If it is empty element then directly check end element.
 				if (reader.IsEmptyElement)
 					goto case XmlNodeType.EndElement;
@@ -671,9 +680,11 @@ namespace Mono.Xml
 				attributePrefixes.Add (attrName, reader.Prefix);
 				XmlReader targetReader = reader;
 				string attrValue = null;
-				if (currentEntityHandling == EntityHandling.ExpandCharEntities)
-					attrValue = reader.Value;
-				else {
+				// It always resolves entity references on attributes (documented as such).
+//				if (currentEntityHandling == EntityHandling.ExpandCharEntities)
+//					attrValue = reader.Value;
+//				else
+				{
 					while (attributeValueEntityStack.Count >= 0) {
 						if (!targetReader.ReadAttributeValue ()) {
 							if (attributeValueEntityStack.Count > 0) {
@@ -1080,6 +1091,8 @@ namespace Mono.Xml
 					return (string) attributeNamespaces [currentAttribute];
 				else if (IsDefault)
 					return String.Empty;
+				else if (nsdecls.Count > 0 && nsdecls [Prefix] != null)
+					return (string) nsdecls [Prefix];
 				else
 					return reader.NamespaceURI;
 			}

+ 5 - 0
mcs/class/System.XML/Test/System.Xml/ChangeLog

@@ -1,3 +1,8 @@
+2005-05-10  Atsushi Enomoto <[email protected]>
+
+	* XmlValidatingReaderTests.cs : fixed TestPreserveEntityNotOnDotNet()
+	  which was regarded as a bug while it was by design.
+
 2005-05-05  Atsushi Enomoto <[email protected]>
 
 	* XmlNamespaceManagerTests.cs : removed more atomizedName tests.

+ 5 - 6
mcs/class/System.XML/Test/System.Xml/XmlValidatingReaderTests.cs

@@ -506,7 +506,7 @@ namespace MonoTests.System.Xml
 		}
 
 		[Test]
-		[Category("NotDotNet")]
+		// it used to be regarded as MS bug but it was not really.
 		public void TestPreserveEntityNotOnDotNet ()
 		{
 			string intSubset = "<!ELEMENT root EMPTY><!ATTLIST root foo CDATA 'foo-def' bar CDATA 'bar-def'><!ENTITY ent 'entity string'>";
@@ -520,8 +520,7 @@ namespace MonoTests.System.Xml
 			AssertEquals ("root", dvr.Name);
 			Assert (dvr.MoveToFirstAttribute ());
 			AssertEquals ("foo", dvr.Name);
-			// MS BUG: it returns "entity string", however, entity should not be exanded.
-			AssertEquals ("&ent;", dvr.Value);
+			AssertEquals ("entity string", dvr.Value);
 			//  ReadAttributeValue()
 			Assert (dvr.ReadAttributeValue ());
 			AssertEquals (XmlNodeType.EntityReference, dvr.NodeType);
@@ -532,7 +531,7 @@ namespace MonoTests.System.Xml
 			// bar
 			Assert (dvr.MoveToNextAttribute ());
 			AssertEquals ("bar", dvr.Name);
-			AssertEquals ("internal &ent; value", dvr.Value);
+			AssertEquals ("internal entity string value", dvr.Value);
 			//  ReadAttributeValue()
 			Assert (dvr.ReadAttributeValue ());
 			AssertEquals (XmlNodeType.Text, dvr.NodeType);
@@ -560,7 +559,7 @@ namespace MonoTests.System.Xml
 			// foo
 			Assert (dvr.MoveToFirstAttribute ());
 			AssertEquals ("foo", dvr.Name);
-			AssertEquals ("&ent;", dvr.Value);
+			AssertEquals ("entity string", dvr.Value);
 			//  ReadAttributeValue()
 			Assert (dvr.ReadAttributeValue ());
 			AssertEquals (XmlNodeType.EntityReference, dvr.NodeType);
@@ -571,7 +570,7 @@ namespace MonoTests.System.Xml
 			// bar
 			Assert (dvr.MoveToNextAttribute ());
 			AssertEquals ("bar", dvr.Name);
-			AssertEquals ("internal &ent; value", dvr.Value);
+			AssertEquals ("internal entity string value", dvr.Value);
 			//  ReadAttributeValue()
 			Assert (dvr.ReadAttributeValue ());
 			AssertEquals (XmlNodeType.Text, dvr.NodeType);