Author: atsushi
Date: 2008-02-04 03:49:05 -0500 (Mon, 04 Feb 2008)
New Revision: 94729

Added:
   trunk/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs
   trunk/mcs/class/System.XML/Test/XmlFiles/xsd/358408.xsd
Modified:
   trunk/mcs/class/System.XML/ChangeLog
   trunk/mcs/class/System.XML/Makefile
   trunk/mcs/class/System.XML/System.Xml.Schema/ChangeLog
   trunk/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs
   trunk/mcs/class/System.XML/System.Xml_test.dll.sources
   trunk/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog
   trunk/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog
Log:
2008-02-04  Atsushi Enomoto <[EMAIL PROTECTED]>

        * XmlSchemaValidator.cs : added couple of null argument check.
          Do not depend on XmlSchemaInfo to retrieve attribute value (it
          could be null).
          Do not practically validate attribute when it is not in validating
          state (i.e. inside xs:any). Fixed bug #358408.

        * XmlSchemaValidatorTests.cs : new. Test for bug #358408.

        * 358408.xsd : new test file.

        * System.Xml_test.dll.sources : added XmlSchemaValidatorTests.cs.
        * Makefile : extra distfiles (358408.xsd).



Modified: trunk/mcs/class/System.XML/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/ChangeLog        2008-02-04 08:36:31 UTC (rev 
94728)
+++ trunk/mcs/class/System.XML/ChangeLog        2008-02-04 08:49:05 UTC (rev 
94729)
@@ -1,3 +1,8 @@
+2008-02-04  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * System.Xml_test.dll.sources : added XmlSchemaValidatorTests.cs.
+       * Makefile : extra distfiles (358408.xsd).
+
 2008-01-15  Gert Driesen  <[EMAIL PROTECTED]>
 
        * System.Xml_test.dll.sources: added XmlParserContextTests.cs.

Modified: trunk/mcs/class/System.XML/Makefile
===================================================================
--- trunk/mcs/class/System.XML/Makefile 2008-02-04 08:36:31 UTC (rev 94728)
+++ trunk/mcs/class/System.XML/Makefile 2008-02-04 08:49:05 UTC (rev 94729)
@@ -73,6 +73,7 @@
        Test/XmlFiles/xsd/multi-schemaLocation.xml \
        Test/XmlFiles/xsd/datatypesTest.xsd \
        Test/XmlFiles/xsd/336625.xsd    \
+       Test/XmlFiles/xsd/358408.xsd    \
        Test/XmlFiles/xsd/77687.xsd     \
        Test/XmlFiles/xsd/77687inc.xsd  \
        Test/XmlFiles/xsd/78985.xml     \

Modified: trunk/mcs/class/System.XML/System.Xml.Schema/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Schema/ChangeLog      2008-02-04 
08:36:31 UTC (rev 94728)
+++ trunk/mcs/class/System.XML/System.Xml.Schema/ChangeLog      2008-02-04 
08:49:05 UTC (rev 94729)
@@ -1,3 +1,11 @@
+2008-02-04  Atsushi Enomoto <[EMAIL PROTECTED]>
+
+       * XmlSchemaValidator.cs : added couple of null argument check.
+         Do not depend on XmlSchemaInfo to retrieve attribute value (it
+         could be null).
+         Do not practically validate attribute when it is not in validating
+         state (i.e. inside xs:any). Fixed bug #358408.
+
 2008-01-12  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * XmlSchemaInference.cs: Fix infinite recursion in TypeInference

Modified: trunk/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs
===================================================================
--- trunk/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs  
2008-02-04 08:36:31 UTC (rev 94728)
+++ trunk/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs  
2008-02-04 08:49:05 UTC (rev 94729)
@@ -255,40 +255,47 @@
                                typeof (XmlSchemaParticle));
                }
 
-               public void GetUnspecifiedDefaultAttributes (ArrayList list)
+               public void GetUnspecifiedDefaultAttributes (ArrayList 
defaultAttributeList)
                {
+                       if (defaultAttributeList == null)
+                               throw new ArgumentNullException 
("defaultAttributeList");
+
                        if (transition != Transition.StartTag)
                                throw new InvalidOperationException ("Method 
'GetUnsoecifiedDefaultAttributes' works only when the validator state is inside 
a start tag.");
                        foreach (XmlSchemaAttribute attr
                                in GetExpectedAttributes ())
                                if (attr.ValidatedDefaultValue != null || 
attr.ValidatedFixedValue != null)
-                                       list.Add (attr);
+                                       defaultAttributeList.Add (attr);
 
-                       list.AddRange (defaultAttributes);
+                       defaultAttributeList.AddRange (defaultAttributes);
                }
 
                // State Controller
 
                public void AddSchema (XmlSchema schema)
                {
+                       if (schema == null)
+                               throw new ArgumentNullException ("schema");
                        schemas.Add (schema);
                        schemas.Compile ();
                }
 
                public void Initialize ()
                {
-                       Initialize (null);
-               }
-
-               public void Initialize (SOMObject startType)
-               {
-                       this.startType = startType;
                        transition = Transition.Content;
                        state = new XsdParticleStateManager ();
                        if (!schemas.IsCompiled)
                                schemas.Compile ();
                }
 
+               public void Initialize (SOMObject partialValidationType)
+               {
+                       if (partialValidationType == null)
+                               throw new ArgumentNullException 
("partialValidationType");
+                       this.startType = partialValidationType;
+                       Initialize ();
+               }
+
                // It must be called at the end of the validation (to check
                // identity constraints etc.).
                public void EndValidation ()
@@ -324,8 +331,15 @@
                        string attributeValue,
                        XmlSchemaInfo info)
                {
+                       if (attributeValue == null)
+                               throw new ArgumentNullException 
("attributeValue");
                        return ValidateAttribute (localName, ns,
-                               delegate () { return 
info.SchemaType.Datatype.ParseValue (attributeValue, nameTable, nsResolver); },
+                               delegate () {
+                                       if (info != null && info.SchemaType != 
null && info.SchemaType.Datatype != null)
+                                               return 
info.SchemaType.Datatype.ParseValue (attributeValue, nameTable, nsResolver);
+                                       else
+                                               return attributeValue;
+                               },
                                info);
                }
 
@@ -333,7 +347,7 @@
                // value might not be required (and thus it improves 
                // performance in some cases. Doh).
 
-               // The return value is typed primitive, is possible.
+               // The return value is typed primitive, if possible.
                // AttDeriv
                public object ValidateAttribute (
                        string localName,
@@ -341,6 +355,13 @@
                        XmlValueGetter attributeValue,
                        XmlSchemaInfo info)
                {
+                       if (localName == null)
+                               throw new ArgumentNullException ("localName");
+                       if (ns == null)
+                               throw new ArgumentNullException ("ns");
+                       if (attributeValue == null)
+                               throw new ArgumentNullException 
("attributeValue");
+
                        CheckState (Transition.StartTag);
 
                        QName qname = new QName (localName, ns);
@@ -354,11 +375,14 @@
                        if (schemas.Count == 0)
                                return null;
 
-                       // 3.3.4 Element Locally Valid (Type) - attribute
-                       if (Context.ActualType is ComplexType)
-                               return AssessAttributeElementLocallyValidType 
(localName, ns, attributeValue, info);
-                       else
-                               HandleError ("Current simple type cannot accept 
attributes other than schema instance namespace.");
+                       if (Context.Element != null && Context.XsiType == null) 
{
+
+                               // 3.3.4 Element Locally Valid (Type) - 
attribute
+                               if (Context.ActualType is ComplexType)
+                                       return 
AssessAttributeElementLocallyValidType (localName, ns, attributeValue, info);
+                               else
+                                       HandleError ("Current simple type 
cannot accept attributes other than schema instance namespace.");
+                       }
                        return null;
                }
 
@@ -380,6 +404,11 @@
                        string schemaLocation,
                        string noNsSchemaLocation)
                {
+                       if (localName == null)
+                               throw new ArgumentNullException ("localName");
+                       if (ns == null)
+                               throw new ArgumentNullException ("ns");
+
                        CheckState (Transition.Content);
                        transition = Transition.StartTag;
 
@@ -484,6 +513,8 @@
                // or content type validation errors.
                public void ValidateText (string value)
                {
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
                        ValidateText (delegate () { return value; });
                }
 
@@ -491,6 +522,9 @@
                // ValidateAtomicValue().
                public void ValidateText (XmlValueGetter getter)
                {
+                       if (getter == null)
+                               throw new ArgumentNullException ("getter");
+
                        CheckState (Transition.Content);
                        if (schemas.Count == 0)
                                return;
@@ -514,6 +548,8 @@
 
                public void ValidateWhitespace (string value)
                {
+                       if (value == null)
+                               throw new ArgumentNullException ("value");
                        ValidateWhitespace (delegate () { return value; });
                }
 
@@ -788,7 +824,7 @@
                                try {
                                        parsedValue = getter ();
                                } catch (Exception ex) { // It is inevitable 
and bad manner.
-                                       HandleError ("Attribute value is 
invalid against its data type " + dt.TokenizedType, ex);
+                                       HandleError (String.Format ("Attribute 
value is invalid against its data type {0}", dt != null ? dt.TokenizedType : 
default (XmlTokenizedType)), ex);
                                }
 
                                // check part of 3.14.4 StringValid

Modified: trunk/mcs/class/System.XML/System.Xml_test.dll.sources
===================================================================
--- trunk/mcs/class/System.XML/System.Xml_test.dll.sources      2008-02-04 
08:36:31 UTC (rev 94728)
+++ trunk/mcs/class/System.XML/System.Xml_test.dll.sources      2008-02-04 
08:49:05 UTC (rev 94729)
@@ -55,6 +55,7 @@
 System.Xml.Schema/XmlSchemaTests.cs
 System.Xml.Schema/XmlSchemaTypeTests.cs
 System.Xml.Schema/XmlSchemaSetTests.cs
+System.Xml.Schema/XmlSchemaValidatorTests.cs
 System.Xml.Serialization/CodeIdentifiersTests.cs
 System.Xml.Serialization/ComplexDataStructure.cs
 System.Xml.Serialization/DeserializeTests.cs

Modified: trunk/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog 2008-02-04 
08:36:31 UTC (rev 94728)
+++ trunk/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog 2008-02-04 
08:49:05 UTC (rev 94729)
@@ -1,3 +1,7 @@
+2008-02-04  Atsushi Enomoto  <[EMAIL PROTECTED]>
+
+       * XmlSchemaValidatorTests.cs : new. Test for bug #358408.
+
 2006-08-04  Atsushi Enomoto  <[EMAIL PROTECTED]>
 
        * XmlSchemaTest.cs : added bug #78985 case.

Added: 
trunk/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs
===================================================================
--- 
trunk/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs    
    2008-02-04 08:36:31 UTC (rev 94728)
+++ 
trunk/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs    
    2008-02-04 08:49:05 UTC (rev 94729)
@@ -0,0 +1,75 @@
+//
+// XmlSchemaValidatorTests.cs
+//
+// Author:
+//     Atsushi Enomoto <[EMAIL PROTECTED]>
+//
+// (C) 2008 Novell Inc.
+//
+
+#if NET_2_0
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Xml;
+using System.Xml.Schema;
+using NUnit.Framework;
+
+namespace MonoTests.System.Xml
+{
+       [TestFixture]
+       public class XmlSchemaValidatorTests
+       {
+               [Test]
+               public void XsdAnyToSkipAttributeValidation ()
+               {
+                       // bug #358408
+                       XmlSchemaSet schemas = new XmlSchemaSet ();
+                       schemas.Add (null, "Test/XmlFiles/xsd/358408.xsd");
+                       XmlSchemaValidator v = new XmlSchemaValidator (
+                               new NameTable (),
+                               schemas,
+                               new XmlNamespaceManager (new NameTable ()),
+                               
XmlSchemaValidationFlags.ProcessIdentityConstraints);
+                       v.Initialize ();
+                       v.ValidateWhitespace (" ");
+                       XmlSchemaInfo info = new XmlSchemaInfo ();
+                       ArrayList list = new ArrayList ();
+
+                       v.ValidateElement ("configuration", "", info, null, 
null, null, null);
+                       v.GetUnspecifiedDefaultAttributes (list);
+                       v.ValidateEndOfAttributes (info);
+
+                       v.ValidateWhitespace (" ");
+
+                       v.ValidateElement ("host", "", info, null, null, null, 
null);
+                       v.ValidateAttribute ("auto-start", "", "true", info);
+                       list.Clear ();
+                       v.GetUnspecifiedDefaultAttributes (list);
+                       v.ValidateEndOfAttributes (info);
+                       v.ValidateEndElement (null);//info);
+
+                       v.ValidateWhitespace (" ");
+
+                       v.ValidateElement ("service-managers", "", info, null, 
null, null, null);
+                       list.Clear ();
+                       v.GetUnspecifiedDefaultAttributes (list);
+                       v.ValidateEndOfAttributes (info);
+
+                       v.ValidateWhitespace (" ");
+
+                       v.ValidateElement ("service-manager", "", info, null, 
null, null, null);
+                       list.Clear ();
+                       v.GetUnspecifiedDefaultAttributes (list);
+                       v.ValidateEndOfAttributes (info);
+
+                       v.ValidateWhitespace (" ");
+
+                       v.ValidateElement ("foo", "", info, null, null, null, 
null);
+                       v.ValidateAttribute ("bar", "", "", info);
+               }
+       }
+}
+
+#endif


Property changes on: 
trunk/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs
___________________________________________________________________
Name: svn:eol-style
   + native

Added: trunk/mcs/class/System.XML/Test/XmlFiles/xsd/358408.xsd
===================================================================
--- trunk/mcs/class/System.XML/Test/XmlFiles/xsd/358408.xsd     2008-02-04 
08:36:31 UTC (rev 94728)
+++ trunk/mcs/class/System.XML/Test/XmlFiles/xsd/358408.xsd     2008-02-04 
08:49:05 UTC (rev 94729)
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="utf-8"?>
+<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" 
xmlns:xs="http://www.w3.org/2001/XMLSchema";>
+  <xs:element name="configuration">
+    <xs:complexType>
+      <xs:sequence>
+        <xs:element name="host">
+          <xs:complexType>
+            <xs:attribute name="auto-start" type="xs:boolean" use="required" />
+          </xs:complexType>
+        </xs:element>
+        <xs:element name="service-managers">
+          <xs:complexType>
+            <xs:sequence>
+              <xs:element maxOccurs="unbounded" name="service-manager">
+                <xs:complexType>
+                  <xs:sequence>
+                    <xs:any minOccurs="0" maxOccurs="unbounded" 
processContents="skip" />
+                  </xs:sequence>
+                </xs:complexType>
+              </xs:element>
+            </xs:sequence>
+          </xs:complexType>
+        </xs:element>
+      </xs:sequence>
+    </xs:complexType>
+  </xs:element>
+</xs:schema>

Modified: trunk/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog
===================================================================
--- trunk/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog      2008-02-04 
08:36:31 UTC (rev 94728)
+++ trunk/mcs/class/System.XML/Test/XmlFiles/xsd/ChangeLog      2008-02-04 
08:49:05 UTC (rev 94729)
@@ -1,3 +1,7 @@
+2008-02-04  Atsushi Enomoto <[EMAIL PROTECTED]>
+
+       * 358408.xsd : new test file.
+
 2007-10-31  Atsushi Enomoto <[EMAIL PROTECTED]>
 
        * 336625.xsd : new test file.

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to