Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAtsushi Eno <atsushieno@veritas-vos-liberabit.com>2013-08-07 20:00:10 +0400
committerAtsushi Eno <atsushieno@veritas-vos-liberabit.com>2013-08-07 20:00:10 +0400
commit874d3b13891bb8e804ddbace307a3e1e26f72125 (patch)
tree37195e957312b0e996be2aaf837245072df6ed57 /mcs/class/System.XML
parent155df94118af1c39a52d0080aaca4687d4caae14 (diff)
Fix bug #12035 - xsi:nil='true' was ignored in some scenario.
"some scenario" I mean: - There is a sequence with more than one elements in xsd, - The second element is nillable and its type has content elements, and - The corresponding XML element specifies xsi:nil='true' Then it resulted in a validation error as if it were missing the required content.
Diffstat (limited to 'mcs/class/System.XML')
-rw-r--r--mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs2
-rw-r--r--mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs7
-rw-r--r--mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs44
3 files changed, 49 insertions, 4 deletions
diff --git a/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs b/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs
index 7f19ce58d3d..f6b56c6b3c6 100644
--- a/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs
+++ b/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs
@@ -473,7 +473,7 @@ namespace Mono.Xml.Schema
private void ValidateEndElementParticle ()
{
- if (Context.State != null) {
+ if (xsiNilDepth < 0 && Context.State != null) {
if (!Context.EvaluateEndElement ()) {
HandleError ("Invalid end element: " + reader.Name);
}
diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs
index 92274b2e157..286963d3056 100644
--- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs
+++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs
@@ -539,10 +539,10 @@ namespace System.Xml.Schema
if (skipValidationDepth < 0 || depth <= skipValidationDepth)
AssessCloseStartElementSchemaValidity (schemaInfo);
- depth++;
} finally {
current_info = null;
occuredAtts.Clear ();
+ depth++;
}
}
@@ -976,7 +976,7 @@ namespace System.Xml.Schema
private void ValidateEndElementParticle ()
{
- if (Context.State != null) {
+ if (xsiNilDepth < 0 && Context.State != null) {
if (!Context.EvaluateEndElement ()) {
HandleError ("Invalid end element. There are still required content items.");
}
@@ -1588,7 +1588,8 @@ namespace System.Xml.Schema
if (value == "true") {
if (element.ValidatedFixedValue != null)
HandleError ("Schema instance nil was specified, where the element declaration for " + element.QualifiedName + "has fixed value constraints.");
- xsiNilDepth = depth;
+ if (xsiNilDepth < 0)
+ xsiNilDepth = depth;
if (info != null)
info.IsNil = true;
}
diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs
index bf258f6cc17..6f7ec34a5dd 100644
--- a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs
+++ b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaValidatorTests.cs
@@ -397,6 +397,50 @@ namespace MonoTests.System.Xml
i++;
Assert.AreEqual (2, i, "#2");
}
+
+ [Test]
+ public void Bug12035 ()
+ {
+ string xml = @"<UserSettings
+ xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
+ xmlns:xsd='http://www.w3.org/2001/XMLSchema'
+ xmlns='http://schema/test'><Enabled>false</Enabled><Time xsi:nil='true' /></UserSettings>";
+ string xsd = @"<?xml version='1.0' encoding='utf-8'?>
+<xs:schema
+ targetNamespace='http://schema/test'
+ xmlns='http://schema/test'
+ xmlns:xs='http://www.w3.org/2001/XMLSchema'
+ elementFormDefault='qualified'>
+ <xs:element name='UserSettings'>
+ <xs:complexType>
+ <xs:sequence>
+ <xs:element name='Enabled' type='xs:boolean' />
+ <xs:element name='Time' type='CoarseTime' nillable='true' />
+ </xs:sequence>
+ </xs:complexType>
+ </xs:element>
+
+ <xs:complexType name='CoarseTime'>
+ <xs:sequence>
+ <xs:element name='Hours' type='xs:int' />
+ </xs:sequence>
+ </xs:complexType>
+</xs:schema>";
+ var schema = XmlSchema.Read (new StringReader (xsd), null);
+ var schemaSet = new XmlSchemaSet ();
+ schemaSet.Add (schema);
+ var xmlReaderSettings = new XmlReaderSettings { ValidationType = ValidationType.Schema };
+ xmlReaderSettings.ValidationFlags |= XmlSchemaValidationFlags.ReportValidationWarnings;
+ xmlReaderSettings.Schemas.Add (schemaSet);
+
+ using (var configStream = new StringReader (xml)) {
+ using (var validatingReader = XmlReader.Create (configStream, xmlReaderSettings)) {
+ // Read the XML, throwing an exception if a validation error occurs
+ while (validatingReader.Read()) {
+ }
+ }
+ }
+ }
}
}