[Mono-bugs] [Bug 502168] New: Xml schema validation: Group references handled incorrectly in some cases (Patch included)

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Fri May 8 10:32:01 EDT 2009


http://bugzilla.novell.com/show_bug.cgi?id=502168


           Summary: Xml schema validation: Group references handled
                    incorrectly in some cases (Patch included)
    Classification: Mono
           Product: Mono: Class Libraries
           Version: 2.4.x
          Platform: i686
        OS/Version: Ubuntu
            Status: NEW
          Severity: Normal
          Priority: P5 - None
         Component: Sys.XML
        AssignedTo: atsushi at ximian.com
        ReportedBy: jonas.larsson at manodo.se
         QAContact: mono-bugs at lists.ximian.com
          Found By: ---


Created an attachment (id=291005)
 --> (http://bugzilla.novell.com/attachment.cgi?id=291005)
Patch for this bug

User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10)
Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10

There is a bug in monos handling of xml schema group references. I shows
itself if the same group is used in different contexts. I have tried
to keep the length of the following test code to a minimum, but it's still
quite long. Sorry for that! (Original schema is ~4k lines!)

Test code
On mono it will fail with "Invalid complex content extension was found."
net works ok.
---------------

 string xsd = @"<xs:schema id='Layout'
                  targetNamespace='foo'
                  elementFormDefault='qualified'
                  xmlns='foo'                  
                  xmlns:xs='http://www.w3.org/2001/XMLSchema'>

 <xs:element name='Layout' type='Layout' />

 <xs:complexType name='Layout'>
  <xs:group ref='AnyLayoutElement' minOccurs='0' maxOccurs='unbounded' />
 </xs:complexType>

 <xs:group name='AnyLayoutElement'>
  <xs:choice>
   <xs:element name='Layout' type='Layout' />   
   <xs:element name='ImageContainer' type='ImageContainer' />
   <xs:element name='VideoInstance' type='VideoInstance'/>
  </xs:choice>
 </xs:group>

 <xs:complexType name='ImageDummy'>
 </xs:complexType>

 <xs:complexType name='LayoutElement' abstract='true'>  
 </xs:complexType>

 <xs:group name='AnyImageElement'>
  <xs:choice>
   <xs:element name='ImageDummy' type='ImageDummy' />
  </xs:choice>
 </xs:group>

 <xs:complexType name='ImageContainer'>
  <xs:complexContent>
   <xs:extension base='LayoutElement'>
    <xs:choice minOccurs='1' maxOccurs='1'>
     <xs:element name='Content' type='SingleImage' minOccurs='1' maxOccurs='1'
nillable='false'/>
    </xs:choice>    
   </xs:extension>
  </xs:complexContent>
 </xs:complexType>

 <xs:complexType name='SingleImage'>
  <xs:group ref='AnyImageElement' minOccurs='1' maxOccurs='1'/>
 </xs:complexType>

 <xs:complexType name='VideoApplicationFile'>
  <xs:complexContent>
   <xs:extension base='VideoInstance'>
    <xs:attribute name='fileName' type='xs:string' use='optional'/>
   </xs:extension>
  </xs:complexContent>
 </xs:complexType>

 <xs:complexType abstract='true' name='Video'>
  <xs:complexContent>
   <xs:extension base='LayoutElement'>
    <xs:group ref='AnyImageElement' minOccurs='0' maxOccurs='1'/>    
   </xs:extension>
  </xs:complexContent>
 </xs:complexType>

 <xs:complexType abstract='true' name='VideoInstance'>
  <xs:complexContent>
   <xs:extension base='Video'>
    <xs:attribute name='name' type='xs:string' use='optional'/>
   </xs:extension>
  </xs:complexContent>
 </xs:complexType>
</xs:schema>";


 XmlDocument doc = new XmlDocument();
 XmlSchema schema = XmlSchema.Read(XmlReader.Create(new StringReader(xsd)),
null);
 doc.LoadXml(@"<Layout xmlns='foo' />");
 doc.Schemas.Add(schema);
 doc.Validate(null); // Mono fails here "Invalid complex content extension was
found."

---------------

Cause:
When calculating OptimizedParticle for XmlSchemaGroupRef a shallow clone of a
previous
calculated optimized particle is created:
OptimizedParticle = OptimizedParticle.GetShallowClone ();

This particle in turn can have an already calculated OptimizedParticle, that's
NOT
guaranteed to be valid in the current context since GroupRef's can be used in
different
contexts.

Solution:
After getting the shallow clone above, set it's optimized particle to null.
This
will stop the old one from being used in an invalid context:
OptimizedParticle.OptimizedParticle = null;

Reproducible: Always

Steps to Reproduce:
Run above test code
Actual Results:  
Validation fails

Expected Results:  
Successful validation

My local changes are starting to pile up now. I don't know how to create a
patch for the unit test, since that file contains several new tests not related
to this bug. Please use the posted code as basis for a unit test.

As with all the patches I submit, I've run all tests with no regressions before
posting.

-- 
Configure bugmail: http://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.


More information about the mono-bugs mailing list