Browse Source

2007-08-02 Atsushi Enomoto <[email protected]>

	* XmlSchemaComplexType.cs,
	  XmlSchemaComplexContentRestriction.cs :
	  in Validate(), every descendant item in complexType must be first
	  validated before getting GetOptimizedParticle(), or it could result
	  in wrong content particle. Fixed bug #82010.

	* XsdValidatingReaderTests.cs : test for bug #82010.

	* 82010.xsd, 82010.xml : new test files.

	* Makefile : extra distfiles (82010.xml/.xsd).


svn path=/trunk/mcs/; revision=83272
Atsushi Eno 18 years ago
parent
commit
b6cbab331e

+ 4 - 0
mcs/class/System.XML/ChangeLog

@@ -1,3 +1,7 @@
+2007-08-02  Atsushi Enomoto  <[email protected]>
+
+	* Makefile : extra distfiles (82010.xml/.xsd).
+
 2007-06-28  Atsushi Enomoto  <[email protected]>
 
 	* System.Xml.dll.sources : added XsltDebuggerWrapper.cs, as initial

+ 2 - 0
mcs/class/System.XML/Makefile

@@ -77,6 +77,8 @@ EXTRA_DISTFILES = \
 	Test/XmlFiles/xsd/78985.xml     \
 	Test/XmlFiles/xsd/78985.xsd     \
 	Test/XmlFiles/xsd/79650.xsd     \
+	Test/XmlFiles/xsd/82010.xml	\
+	Test/XmlFiles/xsd/82010.xsd	\
 	Test/XmlFiles/xsd/inter-inc-1.xsd \
 	Test/XmlFiles/xsl/91834.xml 	\
 	Test/XmlFiles/xsl/91834.xsl 	\

+ 8 - 0
mcs/class/System.XML/System.Xml.Schema/ChangeLog

@@ -1,3 +1,11 @@
+2007-08-02  Atsushi Enomoto <[email protected]>
+
+	* XmlSchemaComplexType.cs,
+	  XmlSchemaComplexContentRestriction.cs :
+	  in Validate(), every descendant item in complexType must be first
+	  validated before getting GetOptimizedParticle(), or it could result
+	  in wrong content particle. Fixed bug #82010.
+
 2007-08-02  Atsushi Enomoto <[email protected]>
 
 	* XmlSchemaValidator.cs : another extra whitespace rejection.

+ 2 - 0
mcs/class/System.XML/System.Xml.Schema/XmlSchemaComplexContentRestriction.cs

@@ -184,6 +184,8 @@ namespace System.Xml.Schema
 
 		internal override int Validate (ValidationEventHandler h, XmlSchema schema)
 		{
+			if (Particle != null)
+				Particle.Validate (h, schema);
 			return errorCount;
 		}
 

+ 29 - 22
mcs/class/System.XML/System.Xml.Schema/XmlSchemaComplexType.cs

@@ -409,13 +409,16 @@ namespace System.Xml.Schema
 			}
 			else
 				resolvedDerivedBy = XmlSchemaDerivationMethod.Empty;
+		}
 
-
+		void FillContentTypeParticle (ValidationEventHandler h, XmlSchema schema)
+		{
 			// {content type} => ContentType and ContentTypeParticle (later)
 			if (ContentModel != null) {
 				CollectContentTypeFromContentModel (h, schema);
 			} else
 				CollectContentTypeFromImmediateContent ();
+
 			contentTypeParticle = validatableParticle.GetOptimizedParticle (true);
 			if (contentTypeParticle == XmlSchemaParticle.Empty && resolvedContentType == XmlSchemaContentType.ElementOnly)
 				resolvedContentType = XmlSchemaContentType.Empty;
@@ -582,6 +585,10 @@ namespace System.Xml.Schema
 
 			CollectSchemaComponent (h, schema);
 
+			ValidateContentFirstPass (h, schema);
+
+			FillContentTypeParticle (h, schema);
+
 			// 3.4.6: Properties Correct
 			// Term. 1 => 3.4.1 already done by CollectSchemaComponent()
 			//	      except for {attribute uses} and {attribute wildcard}
@@ -590,11 +597,8 @@ namespace System.Xml.Schema
 			//
 			if (ContentModel != null)
 				ValidateContentModel (h, schema);
-			else {
-				if (Particle != null)
-					ValidateImmediateParticle (h, schema);
+			else
 				ValidateImmediateAttributes (h, schema);
-			}
 
 			// Additional support for 3.8.6 All Group Limited
 			if (ContentTypeParticle != null) {
@@ -634,19 +638,6 @@ namespace System.Xml.Schema
 			return errorCount;
 		}
 
-		private void ValidateImmediateParticle (ValidationEventHandler h, XmlSchema schema)
-		{
-			errorCount += particle.Validate (h, schema);
-			XmlSchemaGroupRef pgrp = Particle as XmlSchemaGroupRef;
-			if (pgrp != null) {
-				if (pgrp.TargetGroup != null)
-					errorCount += pgrp.TargetGroup.Validate (h,schema);
-				// otherwise, it might be missing sub components.
-				else if (!schema.IsNamespaceAbsent (pgrp.RefName.Namespace))
-					error (h, "Referenced group " + pgrp.RefName + " was not found in the corresponding schema.");
-			}
-		}
-
 		private void ValidateImmediateAttributes (ValidationEventHandler h, XmlSchema schema)
 		{
 			// {attribute uses}
@@ -656,12 +647,31 @@ namespace System.Xml.Schema
 				h, schema, attributes, anyAttribute, ref attributeWildcard, null, false);
 		}
 
+		private void ValidateContentFirstPass (ValidationEventHandler h, XmlSchema schema)
+		{
+			if (ContentModel != null) {
+				errorCount += contentModel.Validate (h, schema);
+				if (BaseXmlSchemaTypeInternal != null)
+					errorCount += BaseXmlSchemaTypeInternal.Validate (h, schema);
+			}
+			else if (Particle != null) {
+				errorCount += particle.Validate (h, schema);
+				XmlSchemaGroupRef pgrp = Particle as XmlSchemaGroupRef;
+				if (pgrp != null) {
+					if (pgrp.TargetGroup != null)
+						errorCount += pgrp.TargetGroup.Validate (h,schema);
+					// otherwise, it might be missing sub components.
+					else if (!schema.IsNamespaceAbsent (pgrp.RefName.Namespace))
+						error (h, "Referenced group " + pgrp.RefName + " was not found in the corresponding schema.");
+				}
+			}
+		}
+
 		private void ValidateContentModel (ValidationEventHandler h, XmlSchema schema)
 		{
 			XmlSchemaType baseType = BaseXmlSchemaTypeInternal;
 
 			// Here we check 3.4.6 Properties Correct :: 2. and 3.
-			errorCount += contentModel.Validate (h, schema);
 			XmlSchemaComplexContentExtension cce = contentModel.Content as XmlSchemaComplexContentExtension;
 			XmlSchemaComplexContentRestriction ccr = contentModel.Content as XmlSchemaComplexContentRestriction;
 			XmlSchemaSimpleContentExtension sce = contentModel.Content as XmlSchemaSimpleContentExtension;
@@ -674,7 +684,6 @@ namespace System.Xml.Schema
 			if (ValidateRecursionCheck ())
 				error (h, "Circular definition of schema types was found.");
 			if (baseType != null) {
-				baseType.Validate (h, schema);
 				// Fill "Datatype" property.
 				this.DatatypeInternal = baseType.Datatype;
 			} else if (BaseSchemaTypeName == XmlSchemaComplexType.AnyTypeName)
@@ -776,8 +785,6 @@ namespace System.Xml.Schema
 				// For ValidationEventHandler.
 				if (baseComplexType == null)
 					baseComplexType = XmlSchemaComplexType.AnyType;
-				if (ccr.Particle != null)
-					ccr.Particle.Validate (h, schema);
 
 				// attributes
 				localAnyAttribute = ccr.AnyAttribute;

+ 1 - 1
mcs/class/System.XML/System.Xml.Schema/XmlSchemaGroupRef.cs

@@ -134,7 +134,7 @@ namespace System.Xml.Schema
 			XmlSchemaGroup g = referencedGroup != null ? referencedGroup : schema.Groups [RefName] as XmlSchemaGroup;
 			if (g != null && g.Particle != null) {
 				OptimizedParticle = g.Particle;
-					OptimizedParticle = OptimizedParticle.GetOptimizedParticle (isTop);
+				OptimizedParticle = OptimizedParticle.GetOptimizedParticle (isTop);
 				if (OptimizedParticle != XmlSchemaParticle.Empty && (ValidatedMinOccurs != 1 || ValidatedMaxOccurs != 1)) {
 					OptimizedParticle = OptimizedParticle.GetShallowClone ();
 					OptimizedParticle.MinOccurs = this.MinOccurs;

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

@@ -1,3 +1,7 @@
+2007-08-02  Atsushi Enomoto  <[email protected]>
+
+	* XsdValidatingReaderTests.cs : test for bug #82010.
+
 2007-08-02  Atsushi Enomoto  <[email protected]>
 
 	* XsdValidatingReaderTests.cs : another test posted on bug #82183.

+ 22 - 1
mcs/class/System.XML/Test/System.Xml/XsdValidatingReaderTests.cs

@@ -5,7 +5,7 @@
 //	Atsushi Enomoto <[email protected]>
 //
 // (C)2003 Atsushi Enomoto
-// (C)2005-2006 Novell, Inc.
+// (C)2005-2007 Novell, Inc.
 //
 using System;
 using System.IO;
@@ -432,6 +432,27 @@ namespace MonoTests.System.Xml
 			reader.Read ();
 		}
 
+		[Test]
+		public void Bug82010 ()
+		{
+			string xmlfile = "Test/XmlFiles/xsd/82010.xml";
+			string xsdfile = "Test/XmlFiles/xsd/82010.xsd";
+			XmlTextReader xr = null, xr2 = null;
+			try {
+				xr = new XmlTextReader (xsdfile);
+				xr2 = new XmlTextReader (xmlfile);
+				XmlValidatingReader xvr = new XmlValidatingReader (xr2);
+				xvr.Schemas.Add (XmlSchema.Read (xr, null));
+				while (!xvr.EOF)
+					xvr.Read ();
+			} finally {
+				if (xr2 != null)
+					xr2.Close ();
+				if (xr != null)
+					xr.Close ();
+			}
+		}
+
 #if NET_2_0
 		[Test]
 		public void WhitespaceAndElementOnly ()

+ 7 - 0
mcs/class/System.XML/Test/XmlFiles/xsd/82010.xml

@@ -0,0 +1,7 @@
+<Document>
+   <SimpleCodeList>
+      <Row/>
+      <Row/>
+   </SimpleCodeList>
+</Document>
+

+ 29 - 0
mcs/class/System.XML/Test/XmlFiles/xsd/82010.xsd

@@ -0,0 +1,29 @@
+<xsd:schema
+    xmlns:xsd="http://www.w3.org/2001/XMLSchema">
+    <xsd:element name="Document" type="Document"/>
+    <xsd:complexType name="Document">
+        <xsd:sequence>
+            <xsd:group ref="OuterCodeListChoice" minOccurs="0"/>
+        </xsd:sequence>
+    </xsd:complexType>
+    <xsd:group name="OuterCodeListChoice">
+        <xsd:choice>
+            <xsd:group ref="SimpleCodeListSequence"/>
+        </xsd:choice>
+    </xsd:group>
+    <xsd:complexType name="Row">
+        <xsd:sequence>
+        </xsd:sequence>
+    </xsd:complexType>
+    <xsd:complexType name="SimpleCodeList">
+        <xsd:sequence>
+            <xsd:element name="Row" minOccurs="0" maxOccurs="unbounded" type="Row"/>
+        </xsd:sequence>
+    </xsd:complexType>
+    <xsd:group name="SimpleCodeListSequence">
+        <xsd:sequence>
+            <xsd:element name="SimpleCodeList" type="SimpleCodeList"/>
+        </xsd:sequence>
+    </xsd:group>
+</xsd:schema>
+

+ 4 - 0
mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog

@@ -1,3 +1,7 @@
+2007-08-02  Atsushi Enomoto <[email protected]>
+
+	* 82010.xsd, 82010.xml : new test files.
+
 2007-04-24  Atsushi Enomoto <[email protected]>
 
 	* 81360.xsd, 81360inc1.xsd, 81360inc2.xsd : new test files.