From: Atsushi Eno Date: Mon, 9 May 2011 10:09:19 +0000 (+0900) Subject: Multiple schemas in wsdl could share same SourceUri, so check more identity. X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=b523f411bd35d8be7ef48cced4a9622223a88258;p=mono.git Multiple schemas in wsdl could share same SourceUri, so check more identity. Part of bugfix #670945. --- diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs index 13b8b9f6a71..6f1a4c40dd6 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs @@ -28,6 +28,7 @@ // using System; using System.Collections; +using System.Collections.Generic; using System.Xml; using System.IO; using System.Xml.Serialization; @@ -291,21 +292,30 @@ namespace System.Xml.Schema // It is used by XmlSchemaCollection.Add() and XmlSchemaSet.Remove(). internal void CompileSubset (ValidationEventHandler handler, XmlSchemaSet col, XmlResolver resolver) { - Hashtable handledUris = new Hashtable (); + var handledUris = new List (); CompileSubset (handler, col, resolver, handledUris); } // It is used by XmlSchemaSet.Compile(). - internal void CompileSubset (ValidationEventHandler handler, XmlSchemaSet col, XmlResolver resolver, Hashtable handledUris) + internal void CompileSubset (ValidationEventHandler handler, XmlSchemaSet col, XmlResolver resolver, List handledUris) { if (SourceUri != null && SourceUri.Length > 0) { - if (handledUris.Contains (SourceUri)) + // if it has line info and are the same as one of existing info, then skip it. + if (Contains (handledUris)) return; - handledUris.Add (SourceUri, SourceUri); + handledUris.Add (new CompiledSchemaMemo () { SourceUri = this.SourceUri, LineNumber = this.LineNumber, LinePosition = this.LinePosition}); } DoCompile (handler, handledUris, col, resolver); } + bool Contains (List handledUris) + { + foreach (var i in handledUris) + if (i.SourceUri.Equals (SourceUri) && i.LineNumber != 0 && i.LineNumber == LineNumber && i.LinePosition == LinePosition) + return true; + return false; + } + void SetParent () { for (int i = 0; i < Items.Count; i++) @@ -314,7 +324,7 @@ namespace System.Xml.Schema Includes [i].SetParent (this); } - void DoCompile (ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver) + void DoCompile (ValidationEventHandler handler, List handledUris, XmlSchemaSet col, XmlResolver resolver) { SetParent (); CompilationId = col.CompilationId; @@ -477,7 +487,7 @@ namespace System.Xml.Schema #endif } - void ProcessExternal (ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaExternal ext, XmlSchemaSet col) + void ProcessExternal (ValidationEventHandler handler, List handledUris, XmlResolver resolver, XmlSchemaExternal ext, XmlSchemaSet col) { if (ext == null) { error (handler, String.Format ("Object of Type {0} is not valid in Includes Property of XmlSchema", ext.GetType().Name)); @@ -496,10 +506,11 @@ namespace System.Xml.Schema string url = null; if (resolver != null) { url = GetResolvedUri (resolver, ext.SchemaLocation); - if (handledUris.Contains (url)) - // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur. - return; - handledUris.Add (url, url); + foreach (var i in handledUris) + if (i.SourceUri.Equals (url)) + // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur. + return; + handledUris.Add (new CompiledSchemaMemo () { SourceUri = url }); try { stream = resolver.GetEntity (new Uri (url), null, typeof (Stream)) as Stream; } catch (Exception) { @@ -589,7 +600,7 @@ namespace System.Xml.Schema } - void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaSet col) + void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, List handledUris, XmlResolver resolver, XmlSchemaSet col) { foreach (XmlSchemaExternal ext in s.Includes) s.ProcessExternal (handler, handledUris, resolver, ext, col); @@ -992,4 +1003,11 @@ namespace System.Xml.Schema return new XmlSchemaSerializationWriter (); } } + + class CompiledSchemaMemo + { + public string SourceUri; + public int LineNumber; + public int LinePosition; + } } diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaObject.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaObject.cs index 6f1f3f7ebfa..d3de335fb9b 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaObject.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaObject.cs @@ -45,7 +45,7 @@ namespace System.Xml.Schema internal ArrayList unhandledAttributeList ; internal bool isCompiled = false; internal int errorCount = 0; - internal Guid CompilationId; + internal Guid compilation_id; internal Guid ValidationId; internal bool isRedefineChild; internal bool isRedefinedComponent; @@ -58,7 +58,16 @@ namespace System.Xml.Schema { namespaces = new XmlSerializerNamespaces(); unhandledAttributeList = null; - CompilationId = Guid.Empty; + compilation_id = Guid.Empty; + } + + internal Guid CompilationId { + get { return compilation_id; } + set { + if (value.Equals (Guid.Empty)) + throw new ArgumentException ("value must not be empty"); + compilation_id = value; + } } [XmlIgnore] diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs index c304f4cb173..2088dd60b0e 100644 --- a/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs +++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchemaSet.cs @@ -30,6 +30,7 @@ // using System; using System.Collections; +using System.Collections.Generic; using System.Collections.Specialized; using System.ComponentModel; using System.IO; @@ -62,7 +63,7 @@ namespace System.Xml.Schema bool isCompiled; - internal Guid CompilationId; + internal Guid CompilationId { get; private set; } public XmlSchemaSet () : this (new NameTable ()) @@ -199,7 +200,7 @@ namespace System.Xml.Schema IDCollection.Clear (); NamedIdentities.Clear (); - Hashtable handledUris = new Hashtable (); + var handledUris = new List (); foreach (XmlSchema schema in al) if (!schema.IsCompiled) schema.CompileSubset (ValidationEventHandler, this, xmlResolver, handledUris); diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs index d5078cbc5af..6a8a7a49d8a 100644 --- a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs +++ b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaSetTests.cs @@ -218,6 +218,67 @@ type=""xsd:string"" use=""required""/> var xsd = schemas.Add ("", XmlReader.Create (new StringReader (xsdraw))); Assert.IsNull (xsd.TargetNamespace, "#1"); } + + [Test] // part of bug #670945 + public void TwoSchemasInSameDocumentUri () + { + string xsd1 = @" + + + + + + + + + + + + + + + + + "; + + string xsd2 = @" + + + + + + + + + + + + + + + "; + + var xss = new XmlSchemaSet (); + var xs1 = XmlSchema.Read (new StringReader (xsd1), null); + xs1.SourceUri = "http://localhost:8080/dummy.wsdl"; + xs1.LineNumber = 5; + xss.Add (xs1); + var xs2 = XmlSchema.Read (new StringReader (xsd2), null); + xs2.SourceUri = "http://localhost:8080/dummy.wsdl"; + xs2.LineNumber = 50; + xss.Add (xs2); + xss.Compile (); + Assert.IsNotNull (xss.GlobalElements [new XmlQualifiedName ("GetSystemDateAndTimeResponse", "http://www.onvif.org/ver10/device/wsdl")], "#1"); + } } } #endif