Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGert Driesen <drieseng@users.sourceforge.net>2006-02-28 22:18:36 +0300
committerGert Driesen <drieseng@users.sourceforge.net>2006-02-28 22:18:36 +0300
commit181d10350c45a24acf0e79dabdaeb3acd03fc1aa (patch)
tree08e7f938e95ceedff14c3f1270a5fb511298da9f
parentc0fea8c79efa5b43f1afa52290f75411ac923ac9 (diff)
* XmlSchema.cs: Do not define namespace for zero-length TargetNamespace
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
-rw-r--r--mcs/class/System.XML/System.Xml.Schema/ChangeLog6
-rw-r--r--mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs5
-rw-r--r--mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog7
-rw-r--r--mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs27
4 files changed, 42 insertions, 3 deletions
diff --git a/mcs/class/System.XML/System.Xml.Schema/ChangeLog b/mcs/class/System.XML/System.Xml.Schema/ChangeLog
index f63091447d8..8b742ced204 100644
--- a/mcs/class/System.XML/System.Xml.Schema/ChangeLog
+++ b/mcs/class/System.XML/System.Xml.Schema/ChangeLog
@@ -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
diff --git a/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs b/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs
index c415f13c6f8..10fdeedadc2 100644
--- a/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs
+++ b/mcs/class/System.XML/System.Xml.Schema/XmlSchema.cs
@@ -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);
}
diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog b/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog
index fd3032e8ad0..74cc73333c9 100644
--- a/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog
+++ b/mcs/class/System.XML/Test/System.Xml.Schema/ChangeLog
@@ -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.
diff --git a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs
index cf2e11bf26b..ceb0c971933 100644
--- a/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs
+++ b/mcs/class/System.XML/Test/System.Xml.Schema/XmlSchemaTests.cs
@@ -132,11 +132,24 @@ namespace MonoTests.System.Xml
[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 ();
+ 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 ();