From b1f5c86b6a7e2538a69a257311380c25b0f61429 Mon Sep 17 00:00:00 2001 From: Jos Verburg Date: Fri, 3 May 2019 15:00:36 +0200 Subject: [PATCH 1/3] Determine the anyAttribute Namespace based on the NamespaceList --- .../Xml/Schema/XmlSchemaAnyAttribute.cs | 2 +- .../XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs | 81 ++++++++++++++++--- 2 files changed, 70 insertions(+), 13 deletions(-) diff --git a/src/System.Private.Xml/src/System/Xml/Schema/XmlSchemaAnyAttribute.cs b/src/System.Private.Xml/src/System/Xml/Schema/XmlSchemaAnyAttribute.cs index 9ed496b158d3..7fb2547443c5 100644 --- a/src/System.Private.Xml/src/System/Xml/Schema/XmlSchemaAnyAttribute.cs +++ b/src/System.Private.Xml/src/System/Xml/Schema/XmlSchemaAnyAttribute.cs @@ -17,7 +17,7 @@ public class XmlSchemaAnyAttribute : XmlSchemaAnnotated [XmlAttribute("namespace")] public string Namespace { - get { return _ns; } + get { return _ns ?? NamespaceList.ToString(); } set { _ns = value; } } diff --git a/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs b/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs index 9b63d6e217cb..df1346e899e3 100644 --- a/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs +++ b/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs @@ -5,6 +5,7 @@ using Xunit; using Xunit.Abstractions; using System.IO; +using System.Linq; using System.Xml.Schema; namespace System.Xml.Tests @@ -121,14 +122,28 @@ public XmlSchema GetIntersectionSchema(string ns1, string ns2, string attrNs) return XmlSchema.Read(new StringReader(xsd), null); } + public XmlSchema GetSimpleSchema(string ns, string attrNs) + { + var xsd = @" + + + + + + + "; + + return XmlSchema.Read(new StringReader(xsd), null); + } + //Intersection namespaces [Theory] //[Variation(Desc = "complextype Any ns - ##any, attrgroup Any ns2, allow ns2 attribute")] - [InlineData("##any", "ns2", "ns2", 0)] + [InlineData("##any", "ns2", "ns2", 0, "##targetNamespace")] //[Variation(Desc = "complextype Any ns - ##any, attrgroup Any ns2, not allow ns1 attribute")] [InlineData("##any", "ns2", "ns1", 1)] //[Variation(Desc = "complextype Any ns - ns2, attrgroup Any ##any, allow ns2 attribute")] - [InlineData("ns2", "##any", "ns2", 0)] + [InlineData("ns2", "##any", "ns2", 0, "##targetNamespace")] //[Variation(Desc = "complextype Any ns - ns2, attrgroup Any ##any, not allow ns1 attribute")] [InlineData("ns2", "##any", "ns1", 1)] //[Variation(Desc = "complextype Any ns - ns1 ns2, attrgroup Any ##other, not allow ns1 attribute")] @@ -148,10 +163,10 @@ public XmlSchema GetIntersectionSchema(string ns1, string ns2, string attrNs) //[Variation(Desc = "complextype Any ns - ns1 ns3, attrgroup Any ns1 ns2, not allow ns2 attribute")] [InlineData("ns1 ns3", "ns1 ns2", "ns2", 1)] //[Variation(Desc = "complextype Any ns - ns1 ns3, attrgroup Any ns1 ns2, allow ns1 attribute")] - [InlineData("ns1 ns3", "ns1 ns2", "ns1", 0)] + [InlineData("ns1 ns3", "ns1 ns2", "ns1", 0, "ns1")] //[Variation(Desc = "complextype Any ns - ##other, attrgroup Any ##other, not allow ns1 attribute")] [InlineData("##other", "##other", "ns1", 1)] - public void v1(string ns1, string ns2, string attrNs, int expectedError) + public void v1(string ns1, string ns2, string attrNs, int expectedError, string expectedNs = null) { XmlSchemaSet xss = new XmlSchemaSet(); xss.XmlResolver = new XmlUrlResolver(); @@ -160,26 +175,32 @@ public void v1(string ns1, string ns2, string attrNs, int expectedError) xss.Compile(); Assert.Equal(expectedError, _errorCount); + + if (expectedNs != null) + { + XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t", attrNs)]).AttributeWildcard; + CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace); + } } [Theory] //[Variation(Desc = "basetype Any ns - ##any, derivedType Any ns - ns1, allow ns2 attribute")] - [InlineData("##any", "ns1", "ns2", 0)] + [InlineData("##any", "ns1", "ns2", 0, "##any")] //[Variation(Desc = "basetype Any ns - ns1, derivedType Any ns - ##any, allow ns2 attribute")] - [InlineData("ns1", "##any", "ns2", 0)] + [InlineData("ns1", "##any", "ns2", 0, "##any")] //[Variation(Desc = "basetype Any ns - ns1 ns2, derivedType Any ns - ns2 ns3 , allow ns3 attribute")] - [InlineData("ns1 ns2", "ns2 ns3", "ns3", 0)] + [InlineData("ns1 ns2", "ns2 ns3", "ns3", 0, "ns1 ns2 ##targetNamespace")] //[Variation(Desc = "basetype Any ns - ##other, derivedType Any ns - ##other , not allow current ns")] [InlineData("##other", "##other", "ns1", 1)] //[Variation(Desc = "basetype Any ns - ns1 ns2, derivedType Any ns - ##other , allow ns1")] - [InlineData("ns1 ns2", "##other", "ns1", 0)] + [InlineData("ns1 ns2", "##other", "ns1", 0, "##other")] //[Variation(Desc = "basetype Any ns - ns1 ns2, derivedType Any ns - ##other , allow ns2")] - [InlineData("ns1 ns2", "##other", "ns2", 0)] + [InlineData("ns1 ns2", "##other", "ns2", 0, "##other")] //[Variation(Desc = "basetype Any ns - ##other, derivedType Any ns - ns1 ns2 , allow ns2")] - [InlineData("##other", "ns1 ns2", "ns1", 0)] + [InlineData("##other", "ns1 ns2", "ns1", 0, "##other")] //[Variation(Desc = "basetype Any ns - ##other, derivedType Any ns - ns1 ns2 , allow ns2")] - [InlineData("##other", "ns1 ns2", "ns2", 0)] - public void v2(string ns1, string ns2, string attrNs, int expectedError) + [InlineData("##other", "ns1 ns2", "ns2", 0, "##other")] + public void v2(string ns1, string ns2, string attrNs, int expectedError, string expectedNs = null) { XmlSchemaSet xss = new XmlSchemaSet(); xss.XmlResolver = new XmlUrlResolver(); @@ -188,6 +209,42 @@ public void v2(string ns1, string ns2, string attrNs, int expectedError) xss.Compile(); Assert.Equal(expectedError, _errorCount); + + if (expectedNs != null) + { + XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t1", attrNs)]).AttributeWildcard; + CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace); + } + } + + [Theory] + //[Variation(Desc = "ns - ##any, allow any attribute")] + [InlineData("##any", "ns1", "##any")] + //[Variation(Desc = "ns - ##other, not allow ns1 attribute")] + [InlineData("##other", "ns1", "##other")] + //[Variation(Desc = "ns - ns1 ns2, allow ns1 and ns2 attribute")] + [InlineData("ns1 ns2", "ns1", "ns1 ns2")] + //[Variation(Desc = "##targetNamespace, allow current ns")] + [InlineData("##targetNamespace", "ns1", "##targetNamespace")] + public void v3(string ns, string attrNs, string expectedNs) + { + XmlSchemaSet xss = new XmlSchemaSet(); + xss.XmlResolver = new XmlUrlResolver(); + xss.ValidationEventHandler += new ValidationEventHandler(ValidationCallback); + xss.Add(GetSimpleSchema(ns, attrNs)); + xss.Compile(); + + XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t", attrNs)]).AttributeWildcard; + CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace); + } + + private static void CompareWildcardNamespaces(string expected, string actual) + { + Action[] inspectors = expected.Split(' ').OrderBy(ns => ns).Select(expectedNs => new Action(actualNs => { + Assert.Equal(expectedNs, actualNs); + })).ToArray(); + Assert.NotNull(actual); + Assert.Collection(actual.Split(' ').OrderBy(ns => ns), inspectors); } } } From e02f6b060cf7571c3024c2bb4101043607ba6921 Mon Sep 17 00:00:00 2001 From: Jos Verburg Date: Tue, 7 May 2019 14:50:48 +0200 Subject: [PATCH 2/3] Do not test the namespace attribute for full framework for intersection and union cases --- .../XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs b/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs index df1346e899e3..88f16d516d1a 100644 --- a/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs +++ b/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs @@ -176,7 +176,8 @@ public void v1(string ns1, string ns2, string attrNs, int expectedError, string Assert.Equal(expectedError, _errorCount); - if (expectedNs != null) + // Full framework does not set the namespace property for intersections and unions + if (!PlatformDetection.IsFullFramework && expectedNs != null) { XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t", attrNs)]).AttributeWildcard; CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace); @@ -210,7 +211,8 @@ public void v2(string ns1, string ns2, string attrNs, int expectedError, string Assert.Equal(expectedError, _errorCount); - if (expectedNs != null) + // Full framework does not set the namespace property for intersections and unions + if (!PlatformDetection.IsFullFramework && expectedNs != null) { XmlSchemaAnyAttribute attributeWildcard = ((XmlSchemaComplexType)xss.GlobalTypes[new XmlQualifiedName("t1", attrNs)]).AttributeWildcard; CompareWildcardNamespaces(expectedNs, attributeWildcard.Namespace); From 511757d97125158ae1f73393e025f7989215a338 Mon Sep 17 00:00:00 2001 From: Jos Verburg Date: Wed, 15 May 2019 09:49:28 +0200 Subject: [PATCH 3/3] Compare namespaces using string comparison in unit tests --- .../XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs b/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs index 88f16d516d1a..5b8be302ff09 100644 --- a/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs +++ b/src/System.Private.Xml/tests/XmlSchema/XmlSchemaSet/TC_SchemaSet_AnyAttribute.cs @@ -242,11 +242,10 @@ public void v3(string ns, string attrNs, string expectedNs) private static void CompareWildcardNamespaces(string expected, string actual) { - Action[] inspectors = expected.Split(' ').OrderBy(ns => ns).Select(expectedNs => new Action(actualNs => { - Assert.Equal(expectedNs, actualNs); - })).ToArray(); - Assert.NotNull(actual); - Assert.Collection(actual.Split(' ').OrderBy(ns => ns), inspectors); + var orderedExpected = string.Join(" ", expected.Split(' ').OrderBy(ns => ns)); + var orderedActual = string.Join(" ", actual.Split(' ').OrderBy(ns => ns)); + + Assert.Equal(orderedExpected, orderedActual); } } }