diff --git a/src/libraries/System.Private.Xml/src/Resources/Strings.resx b/src/libraries/System.Private.Xml/src/Resources/Strings.resx index 73ea65d48d848..23846093ce581 100644 --- a/src/libraries/System.Private.Xml/src/Resources/Strings.resx +++ b/src/libraries/System.Private.Xml/src/Resources/Strings.resx @@ -1684,7 +1684,7 @@ Derived attribute's use has to be required if base attribute's use is required. - The {base type definition} must have an {attribute wildcard} and the {target namespace} of the R's {attribute declaration} must be valid with respect to that wildcard. + The base type definition must have an attribute wildcard and the target namespace of the attribute declaration in the 'redefine' must be valid with respect to that wildcard. The base attribute '{0}' whose use = 'required' does not have a corresponding derived attribute while redefining attribute group '{1}'. @@ -1771,10 +1771,10 @@ Values that are declared with fixed='true' in a base type can not be changed in a derived type. - It is an error if 'whiteSpace' is among the members of {facets} of {base type definition}, {value} is 'replace' or 'preserve', and the {value} of the parent 'whiteSpace' is 'collapse'. + It is an error if 'whiteSpace' is among the facets of the type definition, its value is 'replace' or 'preserve', and the value of the parent 'whiteSpace' is 'collapse'. - It is an error if 'whiteSpace' is among the members of {facets} of {base type definition}, {value} is 'preserve', and the {value} of the parent 'whiteSpace' is 'replace'. + It is an error if 'whiteSpace' is among the facets of the type definition, its value is 'preserve', and the value of the parent 'whiteSpace' is 'replace'. There must be no fixed value when an attribute is 'xsi:nil' and has a value of 'true'. diff --git a/src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs b/src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs index 83ac7b192991c..59a5320776db9 100644 --- a/src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs +++ b/src/libraries/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs @@ -7,6 +7,7 @@ using System.IO; using System.Xml.Schema; using System.Collections.Generic; +using System.Text; namespace System.Xml.Tests { @@ -1150,5 +1151,219 @@ public void TotalDigitsParseValue_Succeeds() ss.Compile(); } } + + #region tests causing XmlSchemaException with Sch_WhiteSpaceRestriction1 + public static IEnumerable WhiteSpaceRestriction1_Throws_TestData + { + get + { + return new List() + { + new object[] + { +@" + + + + + + + + + + + + +" + }, + new object[] + { +@" + + + + + + + + + + + + +" + } + }; + } + } + + [Theory] + [MemberData(nameof(WhiteSpaceRestriction1_Throws_TestData))] + public void WhiteSpaceRestriction1_Throws(string schema) + { + XmlSchemaSet ss = new XmlSchemaSet(); + using (StringReader sr = new StringReader(schema)) + using (XmlReader xmlrdr = XmlReader.Create(sr)) + { + ss.Add(null, xmlrdr); + } + + Exception ex = Assert.Throws(() => ss.Compile()); + + Assert.Contains("whiteSpace", ex.Message); + Assert.Contains("collapse", ex.Message); + Assert.Contains("preserve", ex.Message); + Assert.Contains("replace", ex.Message); + } + #endregion + + #region tests causing XmlSchemaException with Sch_WhiteSpaceRestriction2 + public static IEnumerable WhiteSpaceRestriction2_Throws_TestData + { + get + { + return new List() + { + new object[] + { +@" + + + + + + + + + + + + +" + } + }; + } + } + + [Theory] + [MemberData(nameof(WhiteSpaceRestriction2_Throws_TestData))] + public void WhiteSpaceRestriction2_Throws(string schema) + { + XmlSchemaSet ss = new XmlSchemaSet(); + using (StringReader sr = new StringReader(schema)) + using (XmlReader xmlrdr = XmlReader.Create(sr)) + { + ss.Add(null, xmlrdr); + } + + Exception ex = Assert.Throws(() => ss.Compile()); + + Assert.Contains("whiteSpace", ex.Message); + Assert.DoesNotContain("collapse", ex.Message); + Assert.Contains("preserve", ex.Message); + Assert.Contains("replace", ex.Message); + } + #endregion + + #region Attribute Restriction Invalid From WildCard tests + + public static IEnumerable AttributeRestrictionInvalidFromWildCard_Throws_TestData + { + get + { + return new List() + { + new object[] + { + @" + + + + + + + + + + + +" + }, + new object[] + { + @" + + + + + + + + + + + +" + } + }; + } + } + + [Theory] + [MemberData(nameof(AttributeRestrictionInvalidFromWildCard_Throws_TestData))] + public void AttributeRestrictionInvalidFromWildCard_Throws(string schema) + { + XmlSchemaSet ss = new XmlSchemaSet(); + ss.XmlResolver = new FakeXmlResolverAttributeRestriction(); + using (StringReader sr = new StringReader(schema)) + using (XmlReader xmlrdr = XmlReader.Create(sr)) + { + ss.Add(null, xmlrdr); + } + + Exception ex = Assert.Throws(() => ss.Compile()); + + Assert.Contains("wildcard", ex.Message); + Assert.Contains("redefine", ex.Message); + } + + private class FakeXmlResolverAttributeRestriction : XmlResolver + { + public override object GetEntity(Uri absoluteUri, string role, Type ofObjectToReturn) + { + int uriIndex = int.Parse(absoluteUri.Host); + string[] schema = { @" + + + + + + + +", +@" + + + + + + + + +" + }; + + return new MemoryStream(Encoding.UTF8.GetBytes(schema[uriIndex])); + } + } + #endregion } }