From 822de472f225db18fa74ef5796de08a59f995300 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Wed, 15 Apr 2020 12:13:48 -0600 Subject: [PATCH 01/10] Adding unit test to provoke exception using Sch_WhiteSpaceRestriction1 as its message. --- .../XmlSchemaSet/TC_SchemaSet_Compile.cs | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) 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 aafe321747fb9d..8feaf3e10bd3c3 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.RegularExpressions; namespace System.Xml.Tests { @@ -1123,5 +1124,68 @@ 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(); + ss.Add(null, XmlReader.Create(new StringReader(schema))); + + Exception ex = Assert.Throws(() => ss.Compile()); + + // Issue 30218: invalid formatters + // TODO remove once invalid formatter is removed from Sch_WhiteSpaceRestriction1. + Regex rx = new Regex(@"\{[a-zA-Z ]+[^\}]*\}"); + Assert.Empty(rx.Matches(ex.Message)); + + Assert.Contains("whiteSpace", ex.Message); + Assert.Contains("collapse", ex.Message); + Assert.Contains("preserve", ex.Message); + Assert.Contains("replace", ex.Message); + } + #endregion } } From 1bcef893151db214f96008624b9c3648ab386133 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 23 Apr 2020 13:47:09 -0600 Subject: [PATCH 02/10] Fixed test XSD to throw the exception with message Sch_WhiteSpaceRestriction1 --- .../XmlSchemaSet/TC_SchemaSet_Compile.cs | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) 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 8feaf3e10bd3c3..4b048a39ab0752 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 @@ -1138,31 +1138,36 @@ public static IEnumerable WhiteSpaceRestriction1_Throws_TestData - - + + + + + + + " - }//, -// new object[] -// { -//@" -// -// -// -// -// -// -// -// -// -// -// -// -//" -// } + }, + new object[] + { +@" + + + + + + + + + + + + +" + } }; } } From 62e6782444c816f21b3e4dc0e41eebee0eca5ea1 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 23 Apr 2020 13:52:27 -0600 Subject: [PATCH 03/10] Added using block for the XmlReader and StringReader. --- .../tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 4b048a39ab0752..900e087416bf89 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 @@ -1177,7 +1177,11 @@ public static IEnumerable WhiteSpaceRestriction1_Throws_TestData public void WhiteSpaceRestriction1_Throws(string schema) { XmlSchemaSet ss = new XmlSchemaSet(); - ss.Add(null, XmlReader.Create(new StringReader(schema))); + using (StringReader sr = new StringReader(schema)) + using (XmlReader xmlrdr = XmlReader.Create(sr)) + { + ss.Add(null, xmlrdr); + } Exception ex = Assert.Throws(() => ss.Compile()); From f11365e003ede336e76e5452ffbfca3d19fa02ff Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 23 Apr 2020 13:56:53 -0600 Subject: [PATCH 04/10] Removed invalid formatters from Sch_WhiteSpaceRestriction1. --- src/libraries/System.Private.Xml/src/Resources/Strings.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.Xml/src/Resources/Strings.resx b/src/libraries/System.Private.Xml/src/Resources/Strings.resx index 73ea65d48d8480..02ec8953a3830d 100644 --- a/src/libraries/System.Private.Xml/src/Resources/Strings.resx +++ b/src/libraries/System.Private.Xml/src/Resources/Strings.resx @@ -1771,7 +1771,7 @@ 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'. From d56e2d795d436bb21693e6674939330e950a59a1 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 23 Apr 2020 14:06:46 -0600 Subject: [PATCH 05/10] Added unit test that causes an exception to be thrown with message Sch_WhiteSpaceRestriction2. --- .../XmlSchemaSet/TC_SchemaSet_Compile.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) 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 900e087416bf89..71a3639223ee06 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 @@ -1196,5 +1196,59 @@ public void WhiteSpaceRestriction1_Throws(string schema) 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()); + + // Issue 30218: invalid formatters + // TODO remove once invalid formatter is removed from Sch_WhiteSpaceRestriction1. + Regex rx = new Regex(@"\{[a-zA-Z ]+[^\}]*\}"); + Assert.Empty(rx.Matches(ex.Message)); + + Assert.Contains("whiteSpace", ex.Message); + Assert.DoesNotContain("collapse", ex.Message); + Assert.Contains("preserve", ex.Message); + Assert.Contains("replace", ex.Message); + } + #endregion } } From 452a9f8bad7642b26208e326f21ee5cae593eaf3 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 23 Apr 2020 14:11:01 -0600 Subject: [PATCH 06/10] Removed the invalid formatters from Sch_WhiteSpaceRestrictcion2. --- src/libraries/System.Private.Xml/src/Resources/Strings.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.Xml/src/Resources/Strings.resx b/src/libraries/System.Private.Xml/src/Resources/Strings.resx index 02ec8953a3830d..d21a8221ceadc2 100644 --- a/src/libraries/System.Private.Xml/src/Resources/Strings.resx +++ b/src/libraries/System.Private.Xml/src/Resources/Strings.resx @@ -1774,7 +1774,7 @@ 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'. From f759dbeda11e80a9f5c2925e97dbaa55de015b2e Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Thu, 23 Apr 2020 14:25:12 -0600 Subject: [PATCH 07/10] Removed regular expression tests for invalid formatters per feedback on PR#33890 --- .../XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs | 11 ----------- 1 file changed, 11 deletions(-) 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 71a3639223ee06..7d547800def220 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,7 +7,6 @@ using System.IO; using System.Xml.Schema; using System.Collections.Generic; -using System.Text.RegularExpressions; namespace System.Xml.Tests { @@ -1185,11 +1184,6 @@ public void WhiteSpaceRestriction1_Throws(string schema) Exception ex = Assert.Throws(() => ss.Compile()); - // Issue 30218: invalid formatters - // TODO remove once invalid formatter is removed from Sch_WhiteSpaceRestriction1. - Regex rx = new Regex(@"\{[a-zA-Z ]+[^\}]*\}"); - Assert.Empty(rx.Matches(ex.Message)); - Assert.Contains("whiteSpace", ex.Message); Assert.Contains("collapse", ex.Message); Assert.Contains("preserve", ex.Message); @@ -1239,11 +1233,6 @@ public void WhiteSpaceRestriction2_Throws(string schema) Exception ex = Assert.Throws(() => ss.Compile()); - // Issue 30218: invalid formatters - // TODO remove once invalid formatter is removed from Sch_WhiteSpaceRestriction1. - Regex rx = new Regex(@"\{[a-zA-Z ]+[^\}]*\}"); - Assert.Empty(rx.Matches(ex.Message)); - Assert.Contains("whiteSpace", ex.Message); Assert.DoesNotContain("collapse", ex.Message); Assert.Contains("preserve", ex.Message); From 0b02cd28b8642ee623eb4df6bbbe8559bc587f0a Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Mon, 27 Apr 2020 15:07:04 -0600 Subject: [PATCH 08/10] Added unit tests for causing the XmlSchemaException with message Sch_AttributeRestrictionInvalidFromWildcard to be thrown. These cover the throw statement which is not previously covered by unit tests. --- .../XmlSchemaSet/TC_SchemaSet_Compile.cs | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) 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 7d547800def220..849af1baca8c11 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 { @@ -1239,5 +1240,108 @@ public void WhiteSpaceRestriction2_Throws(string schema) 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()); + + // Issue 30218: invalid formatters + // TODO remove once invalid formatter is removed from Sch_AttributeRestrictionInvalidFromWildcard. + Text.RegularExpressions.Regex rx = new Text.RegularExpressions.Regex(@"\{[a-zA-Z ]+[^\}]*\}"); + Assert.Empty(rx.Matches(ex.Message)); + + 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 } } From edc7f998cb7bf891edab7629252783f6eb5dee55 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Mon, 27 Apr 2020 15:15:46 -0600 Subject: [PATCH 09/10] Removed the invalid formatters from Sch_AttributeRestrictionInvalidFromWildcard --- src/libraries/System.Private.Xml/src/Resources/Strings.resx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Private.Xml/src/Resources/Strings.resx b/src/libraries/System.Private.Xml/src/Resources/Strings.resx index d21a8221ceadc2..23846093ce5815 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}'. From 64cd531d07102b58eb862755427e0b653ac15df0 Mon Sep 17 00:00:00 2001 From: Mark Johnson Date: Mon, 27 Apr 2020 15:17:57 -0600 Subject: [PATCH 10/10] Removed regular expression tests for invalid formatters per feedback on PR#33890 --- .../tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_Compile.cs | 5 ----- 1 file changed, 5 deletions(-) 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 849af1baca8c11..540f3d3d2c079a 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 @@ -1302,11 +1302,6 @@ public void AttributeRestrictionInvalidFromWildCard_Throws(string schema) Exception ex = Assert.Throws(() => ss.Compile()); - // Issue 30218: invalid formatters - // TODO remove once invalid formatter is removed from Sch_AttributeRestrictionInvalidFromWildcard. - Text.RegularExpressions.Regex rx = new Text.RegularExpressions.Regex(@"\{[a-zA-Z ]+[^\}]*\}"); - Assert.Empty(rx.Matches(ex.Message)); - Assert.Contains("wildcard", ex.Message); Assert.Contains("redefine", ex.Message); }