* XmlSchema.cs: Do not define namespace for zero-length TargetNamespace
authorGert Driesen <drieseng@users.sourceforge.net>
Tue, 28 Feb 2006 19:18:36 +0000 (19:18 -0000)
committerGert Driesen <drieseng@users.sourceforge.net>
Tue, 28 Feb 2006 19:18:36 +0000 (19:18 -0000)
and report XmlSchemaException when compiling XmlSchema with
zero-length TargetNamespace. Fixes bug #77391.
* XmlSchemaTests.cs: Added test for writing XmlSchema with
zero-length TargetNamespace. Added test for compiling XmlSchema
with zero-length TargetNamespace. Replaced Console.WriteLine with
AssertEquals.

svn path=/trunk/mcs/; revision=57415

mcs/class/System.XML/System.Xml.Schema/ChangeLog
mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs
mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog
mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs

index f63091447d87f98f22bd0082cccd61fbc0805b8a..8b742ced204a2b6766ee428b07408ee86e52540c 100644 (file)
@@ -1,3 +1,9 @@
+2006-02-28  Gert Driesen  <drieseng@users.sourceforge.net>
+
+       * XmlSchema.cs: Do not define namespace for zero-length TargetNamespace
+       and report XmlSchemaException when compiling XmlSchema with
+       zero-length TargetNamespace.
+
 2006-02-01  Atsushi Enomoto <atsushi@ximian.com>
 
        * BuiltInDatatype.cs : anyURI could be such relative path that
index c415f13c6f8a3842b6f5cfb37b7ddf2a375d519d..10fdeedadc2c8ee92c78acd2a31d4ac2b70f8d3f 100644 (file)
@@ -337,6 +337,9 @@ namespace System.Xml.Schema
 
                        //4. targetNamespace should be of type anyURI or absent
                        if (TargetNamespace != null) {
+                               if (TargetNamespace.Length == 0)
+                                       error (handler, "The targetNamespace attribute cannot have have empty string as its value.");
+
                                if(!XmlSchemaUtil.CheckAnyUri (TargetNamespace))
                                        error(handler, TargetNamespace+" is not a valid value for targetNamespace attribute of schema");
                        }
@@ -905,7 +908,7 @@ namespace System.Xml.Schema
                                // Add the xml schema namespace. (It is done 
                                // only when no entry exists in Namespaces).
                                nss.Add ("xs", XmlSchema.Namespace);
-                               if (TargetNamespace != null)
+                               if (TargetNamespace != null && TargetNamespace.Length != 0)
                                        nss.Add ("tns", TargetNamespace);
                        }
 
index fd3032e8ad061c046b0d1978e6461f0e97819748..74cc73333c9a1027fd4cac55efcf3a5cce900afd 100644 (file)
@@ -1,3 +1,10 @@
+2006-02-28  Gert Driesen <drieseng@users.sourceforge.net>
+
+       * XmlSchemaTests.cs: Added test for writing XmlSchema with
+       zero-length TargetNamespace. Added test for compiling XmlSchema
+       with zero-length TargetNamespace. Replaced Console.WriteLine with 
+       AssertEquals.
+
 2006-02-06  Atsushi Enomoto <atsushi@ximian.com>
 
        * XmlSchemaDatatypeTests.cs: (TestAnyType) NotDotNet -> Ignore.
index cf2e11bf26b8bbf96b896e91db9ba117a11c7c0a..ceb0c9719335b5b6e75d63c28c90d7df0bd91cdf 100644 (file)
@@ -130,13 +130,26 @@ namespace MonoTests.System.Xml
                        AssertCompiledElement (element, qname, cType);
                }
 
+               [Test]
+               [ExpectedException (typeof (XmlSchemaException))]
+               public void TestCompile_ZeroLength_TargetNamespace ()
+               {
+                       XmlSchema schema = new XmlSchema ();
+                       schema.TargetNamespace = string.Empty;
+                       Assert (!schema.IsCompiled);
+
+                       // MS.NET 1.x: The Namespace '' is an invalid URI.
+                       // MS.NET 2.0: The targetNamespace attribute cannot have empty string as its value.
+                       schema.Compile (null);
+               }
+
                [Test]
                [ExpectedException (typeof (XmlSchemaException))]
                public void TestCompileNonSchema ()
                {
                        XmlTextReader xtr = new XmlTextReader ("<root/>", XmlNodeType.Document, null);
                        XmlSchema schema = XmlSchema.Read (xtr, null);
-                       xtr.Close ();\r
+                       xtr.Close ();
                }
 
                [Test]
@@ -200,7 +213,17 @@ namespace MonoTests.System.Xml
                        xw = new XmlTextWriter (sw);
                        xs.TargetNamespace = "urn:foo";
                        xs.Write (xw);
-                       Console.WriteLine ("#2", "<xs:schema xmlns:tns=\"urn:foo\" targetNamespace=\"urn:foo\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
+                       doc.LoadXml (sw.ToString ());
+                       AssertEquals ("#2", "<xs:schema xmlns:tns=\"urn:foo\" targetNamespace=\"urn:foo\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
+
+                       // Zero-length TargetNamespace
+                       xs = new XmlSchema ();
+                       sw = new StringWriter ();
+                       xw = new XmlTextWriter (sw);
+                       xs.TargetNamespace = string.Empty;
+                       xs.Write (xw);
+                       doc.LoadXml (sw.ToString ());
+                       AssertEquals ("#2b", "<xs:schema targetNamespace=\"\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" />", doc.DocumentElement.OuterXml);
 
                        // XmlSerializerNamespaces
                        xs = new XmlSchema ();