From 12b7f166b639343c0b87773e7e4af58738f19937 Mon Sep 17 00:00:00 2001 From: Atsushi Eno Date: Fri, 6 Jan 2006 04:47:46 +0000 Subject: 2006-01-06 Atsushi Enomoto * XmlValidatingReader.cs : In ReadTypedValue(), treat Whitespace nodes as target string nodes as well as other text nodes. * XsdValidatingReader.cs : Don't use normalized string as input to AssessStringValid(). It incorrectly invalidates strings against simple types with length- related facets. Now that we don't ignore whitespaces, we need to explicitly allow pure whitespace texts in ElementOnly/Empty model. * XmlSchemaSimpleTypeRestriction.cs : maxLength and minLength were likely to be ignored in ValidateNonListValueWithFacets(). * XmlSchemaValidator.cs : Don't use normalized string value as the input to AssessStringValid(). * XsdValidatingReaderTests.cs : test for ReadTypeValue() that it does not ignore whitespace nodes, and it does not normalize string incorrectly. svn path=/trunk/mcs/; revision=55129 --- mcs/class/System.XML/Mono.Xml.Schema/ChangeLog | 9 +++++++ .../Mono.Xml.Schema/XsdValidatingReader.cs | 7 +++--- mcs/class/System.XML/System.Xml.Schema/ChangeLog | 7 ++++++ .../XmlSchemaSimpleTypeRestriction.cs | 2 +- .../System.Xml.Schema/XmlSchemaValidator.cs | 4 ++-- mcs/class/System.XML/System.Xml/ChangeLog | 5 ++++ .../System.XML/System.Xml/XmlValidatingReader.cs | 1 + mcs/class/System.XML/Test/System.Xml/ChangeLog | 6 +++++ .../Test/System.Xml/XsdValidatingReaderTests.cs | 28 ++++++++++++++++++++++ 9 files changed, 63 insertions(+), 6 deletions(-) (limited to 'mcs/class/System.XML') diff --git a/mcs/class/System.XML/Mono.Xml.Schema/ChangeLog b/mcs/class/System.XML/Mono.Xml.Schema/ChangeLog index 1f45f1b132c..5bda8228106 100644 --- a/mcs/class/System.XML/Mono.Xml.Schema/ChangeLog +++ b/mcs/class/System.XML/Mono.Xml.Schema/ChangeLog @@ -1,3 +1,12 @@ +2006-01-06 Atsushi Enomoto + + * XsdValidatingReader.cs : + Don't use normalized string as input to AssessStringValid(). It + incorrectly invalidates strings against simple types with length- + related facets. + Now that we don't ignore whitespaces, we need to explicitly allow + pure whitespace texts in ElementOnly/Empty model. + 2005-12-26 Atsushi Enomoto * XsdValidatingReader.cs : Fixed the bug that only the last schema diff --git a/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs b/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs index 056adeeaa1d..3d712392ec4 100644 --- a/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs +++ b/mcs/class/System.XML/Mono.Xml.Schema/XsdValidatingReader.cs @@ -526,7 +526,7 @@ namespace Mono.Xml.Schema switch (ct.ContentType) { case XmlSchemaContentType.ElementOnly: case XmlSchemaContentType.Empty: - if (value.Length > 0) + if (value.Length > 0 && !XmlChar.IsWhitespace (value)) HandleError ("Character content not allowed."); break; } @@ -624,9 +624,9 @@ namespace Mono.Xml.Schema // mmm, will check later. SimpleType baseType = st.BaseXmlSchemaType as SimpleType; if (baseType != null) { - AssessStringValid(baseType, dt, normalized); + AssessStringValid(baseType, dt, value); } - if (!str.ValidateValueWithFacets (normalized, NameTable)) { + if (!str.ValidateValueWithFacets (value, NameTable)) { HandleError ("Specified value was invalid against the facets."); break; } @@ -1595,6 +1595,7 @@ namespace Mono.Xml.Schema case XmlNodeType.CDATA: case XmlNodeType.SignificantWhitespace: + case XmlNodeType.Whitespace: case XmlNodeType.Text: // FIXME: does this check make sense? ComplexType ct = Context.ActualType as ComplexType; diff --git a/mcs/class/System.XML/System.Xml.Schema/ChangeLog b/mcs/class/System.XML/System.Xml.Schema/ChangeLog index 3c2394acacc..1969b4b2ca6 100644 --- a/mcs/class/System.XML/System.Xml.Schema/ChangeLog +++ b/mcs/class/System.XML/System.Xml.Schema/ChangeLog @@ -1,3 +1,10 @@ +2006-01-06 Atsushi Enomoto + + * XmlSchemaSimpleTypeRestriction.cs : maxLength and minLength were + likely to be ignored in ValidateNonListValueWithFacets(). + * XmlSchemaValidator.cs : Don't use normalized string value as the + input to AssessStringValid(). + 2005-12-08 Atsushi Enomoto * XmlSchemaSet.cs : diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleTypeRestriction.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleTypeRestriction.cs index 567efb887d5..2a4a8962c8b 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleTypeRestriction.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSimpleTypeRestriction.cs @@ -694,7 +694,7 @@ namespace System.Xml.Schema if (! ( (dt is XsdQName) || (dt is XsdNotation))) { // Length potentially slower now, so only calculate if needed - if (! (lengthFacet == -1) && (maxLengthFacet == -1) && (minLengthFacet == -1)) { + if (! ((lengthFacet == -1) && (maxLengthFacet == -1) && (minLengthFacet == -1))) { // numeric // : length diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs index 26d5bba0a17..d5702d2445f 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaValidator.cs @@ -1034,9 +1034,9 @@ namespace System.Xml.Schema // mmm, will check later. SimpleType baseType = st.BaseXmlSchemaType as SimpleType; if (baseType != null) { - ret = AssessStringValid (baseType, dt, normalized); + ret = AssessStringValid (baseType, dt, value); } - if (!str.ValidateValueWithFacets (normalized, nameTable)) { + if (!str.ValidateValueWithFacets (value, nameTable)) { HandleError ("Specified value was invalid against the facets."); break; } diff --git a/mcs/class/System.XML/System.Xml/ChangeLog b/mcs/class/System.XML/System.Xml/ChangeLog index 82eca321b54..d30ee0e34e4 100644 --- a/mcs/class/System.XML/System.Xml/ChangeLog +++ b/mcs/class/System.XML/System.Xml/ChangeLog @@ -1,3 +1,8 @@ +2006-01-06 Atsushi Enomoto + + * XmlValidatingReader.cs : In ReadTypedValue(), treat Whitespace + nodes as target string nodes as well as other text nodes. + 2006-01-06 Atsushi Enomoto * XmlValidatingReader.cs : ReadTypedValue() was not working with diff --git a/mcs/class/System.XML/System.Xml/XmlValidatingReader.cs b/mcs/class/System.XML/System.Xml/XmlValidatingReader.cs index 8b22eb6a31e..4a8c3764008 100644 --- a/mcs/class/System.XML/System.Xml/XmlValidatingReader.cs +++ b/mcs/class/System.XML/System.Xml/XmlValidatingReader.cs @@ -564,6 +564,7 @@ namespace System.Xml do { Read (); switch (NodeType) { + case XmlNodeType.Whitespace: case XmlNodeType.SignificantWhitespace: case XmlNodeType.Text: case XmlNodeType.CDATA: diff --git a/mcs/class/System.XML/Test/System.Xml/ChangeLog b/mcs/class/System.XML/Test/System.Xml/ChangeLog index 69ad13b7d2e..d8c563d1bea 100644 --- a/mcs/class/System.XML/Test/System.Xml/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml/ChangeLog @@ -1,3 +1,9 @@ +2006-01-06 Atsushi Enomoto + + * XsdValidatingReaderTests.cs : test for ReadTypeValue() that it + does not ignore whitespace nodes, and it does not normalize string + incorrectly. + 2006-01-06 Atsushi Enomoto * XsdValidatingReaderTests.cs : test for ReadTypeValue() with simple diff --git a/mcs/class/System.XML/Test/System.Xml/XsdValidatingReaderTests.cs b/mcs/class/System.XML/Test/System.Xml/XsdValidatingReaderTests.cs index 407aabb6a16..3ed1698c6b6 100644 --- a/mcs/class/System.XML/Test/System.Xml/XsdValidatingReaderTests.cs +++ b/mcs/class/System.XML/Test/System.Xml/XsdValidatingReaderTests.cs @@ -261,5 +261,33 @@ namespace MonoTests.System.Xml AssertEquals ("xx", vr.ReadTypedValue ()); AssertEquals (XmlNodeType.EndElement, vr.NodeType); } + + // If we normalize string before validating with facets, + // this test will fail. It will also fail if ReadTypedValue() + // ignores whitespace nodes. + [Test] + public void ReadTypedValueWhitespaces () + { + string xml = " "; + string xsd = @" + + + + + + + + +"; + XmlTextReader xir = + new XmlTextReader (xml, XmlNodeType.Document, null); + XmlTextReader xsr = + new XmlTextReader (xsd, XmlNodeType.Document, null); + XmlValidatingReader vr = new XmlValidatingReader (xir); + vr.Schemas.Add (XmlSchema.Read (xsr, null)); + vr.Read (); // root + AssertEquals (" ", vr.ReadTypedValue ()); + AssertEquals (XmlNodeType.EndElement, vr.NodeType); + } } } -- cgit v1.2.3