From cd7644c9972bca5348cdabe1fc1870d65419737b Mon Sep 17 00:00:00 2001 From: Gert Driesen Date: Thu, 5 Jan 2006 20:16:41 +0000 Subject: * XmlTextWriter.cs: Modified WriteWhitespace to throw ArgumentException if value is null or zero-length string. Modified WriteNmToken to throw ArgumentException if name is null or zero-length string. Cosmetic change to WriteStringInternal. * XmlElement.cs: In 2.0 profile, do not throw ArgumentNullException if new value for Prefix is null. * XmlElementTests.cs: Improved tests for setting prefix to null or zero-length string. On 2.0 profile, setting prefix to null should not result in ArgumentNullException. * XmlTextWriterTests.cs: Enabled WriteNmToken tests and WriteWhitespace tests for null or zero-length value. svn path=/trunk/mcs/; revision=55115 --- mcs/class/System.XML/System.Xml/ChangeLog | 9 ++++ mcs/class/System.XML/System.Xml/XmlElement.cs | 9 +++- mcs/class/System.XML/System.Xml/XmlTextWriter.cs | 61 ++++++++++++---------- mcs/class/System.XML/Test/System.Xml/ChangeLog | 8 +++ .../System.XML/Test/System.Xml/XmlElementTests.cs | 30 ++++++++++- .../Test/System.Xml/XmlTextWriterTests.cs | 4 -- 6 files changed, 86 insertions(+), 35 deletions(-) (limited to 'mcs/class/System.XML') diff --git a/mcs/class/System.XML/System.Xml/ChangeLog b/mcs/class/System.XML/System.Xml/ChangeLog index 3cb903a3edb..18062f3d66c 100644 --- a/mcs/class/System.XML/System.Xml/ChangeLog +++ b/mcs/class/System.XML/System.Xml/ChangeLog @@ -1,3 +1,12 @@ +2006-01-05 Gert Driesen + + * XmlTextWriter.cs: Modified WriteWhitespace to throw ArgumentException + if value is null or zero-length string. Modified WriteNmToken to throw + ArgumentException if name is null or zero-length string. Cosmetic + change to WriteStringInternal. + * XmlElement.cs: In 2.0 profile, do not throw ArgumentNullException + if new value for Prefix is null. + 2005-12-26 Atsushi Enomoto * XmlTextWriter.cs : when namespaceURI is String.Empty, Prefix diff --git a/mcs/class/System.XML/System.Xml/XmlElement.cs b/mcs/class/System.XML/System.Xml/XmlElement.cs index b008b0c0ff1..3f90c23030d 100644 --- a/mcs/class/System.XML/System.Xml/XmlElement.cs +++ b/mcs/class/System.XML/System.Xml/XmlElement.cs @@ -216,8 +216,13 @@ namespace System.Xml set { if (IsReadOnly) throw new ArgumentException ("This node is readonly."); - if (value == null) - throw new ArgumentNullException("Prefix value is null."); + if (value == null) { +#if NET_2_0 + value = string.Empty; +#else + throw new ArgumentNullException ("Prefix value is null."); +#endif + } if ((!String.Empty.Equals(value))&&(!XmlChar.IsNCName (value))) throw new ArgumentException ("Specified name is not a valid NCName: " + value); diff --git a/mcs/class/System.XML/System.Xml/XmlTextWriter.cs b/mcs/class/System.XML/System.Xml/XmlTextWriter.cs index 5328ec467af..cc86640a281 100644 --- a/mcs/class/System.XML/System.Xml/XmlTextWriter.cs +++ b/mcs/class/System.XML/System.Xml/XmlTextWriter.cs @@ -683,6 +683,9 @@ openElements [openElementCount - 1]).IndentingOverriden; public override void WriteNmToken (string name) { + if (name == null || name.Length == 0) + throw ArgumentError ("The Name cannot be empty."); + WriteNmTokenInternal (name); } @@ -1077,40 +1080,38 @@ openElements [openElementCount - 1]).IndentingOverriden; private void WriteStringInternal (string text, bool entitize) { - if (text == null) - text = String.Empty; - - if (text != String.Empty) { - CheckState (); + if (text == null || text.Length == 0) + return; + + CheckState (); - if (entitize) - text = EscapeString (text, !openAttribute); + if (entitize) + text = EscapeString (text, !openAttribute); - if (!openAttribute) - { - IndentingOverriden = true; - CloseStartElement (); - } + if (!openAttribute) + { + IndentingOverriden = true; + CloseStartElement (); + } - if (!openXmlLang && !openXmlSpace) - w.Write (text); + if (!openXmlLang && !openXmlSpace) + w.Write (text); + else + { + if (openXmlLang) + xmlLang = text; else { - if (openXmlLang) - xmlLang = text; - else + switch (text) { - switch (text) - { - case "default": - xmlSpace = XmlSpace.Default; - break; - case "preserve": - xmlSpace = XmlSpace.Preserve; - break; - default: - throw ArgumentError ("'{0}' is an invalid xml:space value."); - } + case "default": + xmlSpace = XmlSpace.Default; + break; + case "preserve": + xmlSpace = XmlSpace.Preserve; + break; + default: + throw ArgumentError ("'{0}' is an invalid xml:space value."); } } } @@ -1136,6 +1137,10 @@ openElements [openElementCount - 1]).IndentingOverriden; public override void WriteWhitespace (string ws) { + if (ws == null || ws.Length == 0) { + throw ArgumentError ("Only white space characters should be used."); + } + if (!XmlChar.IsWhitespace (ws)) throw ArgumentError ("Invalid Whitespace"); diff --git a/mcs/class/System.XML/Test/System.Xml/ChangeLog b/mcs/class/System.XML/Test/System.Xml/ChangeLog index 9d34d089bfe..8d80f6e5735 100644 --- a/mcs/class/System.XML/Test/System.Xml/ChangeLog +++ b/mcs/class/System.XML/Test/System.Xml/ChangeLog @@ -1,3 +1,11 @@ +2006-01-05 Gert Driesen + + * XmlElementTests.cs: Improved tests for setting prefix to null + or zero-length string. On 2.0 profile, setting prefix to null should + not result in ArgumentNullException. + * XmlTextWriterTests.cs: Enabled WriteNmToken tests and + WriteWhitespace tests for null or zero-length value. + 2006-01-05 Atsushi Enomoto * XmlTextWriterTests.cs : removed silly part from diff --git a/mcs/class/System.XML/Test/System.Xml/XmlElementTests.cs b/mcs/class/System.XML/Test/System.Xml/XmlElementTests.cs index 89af454522c..bce3a735ef9 100644 --- a/mcs/class/System.XML/Test/System.Xml/XmlElementTests.cs +++ b/mcs/class/System.XML/Test/System.Xml/XmlElementTests.cs @@ -561,20 +561,48 @@ namespace MonoTests.System.Xml } [Test] +#if ONLY_1_1 [ExpectedException (typeof (ArgumentNullException))] +#endif public void SetNullPrefix () { XmlDocument doc = new XmlDocument (); doc.LoadXml (""); doc.DocumentElement.Prefix = null; + +#if NET_2_0 + AssertEquals ("#1", string.Empty, doc.DocumentElement.Prefix); + AssertClearPrefix ((string) null); +#endif } [Test] public void SetEmptyStringPrefix () { XmlDocument doc = new XmlDocument (); - doc.LoadXml (""); + doc.LoadXml (""); doc.DocumentElement.Prefix = String.Empty; + AssertEquals ("#1", string.Empty, doc.DocumentElement.Prefix); + + AssertClearPrefix (string.Empty); + + } + + private void AssertClearPrefix (string newPrefix) + { + XmlDocument doc = new XmlDocument (); + doc.LoadXml (""); + AssertEquals ("#Clear1", "", + doc.OuterXml); + AssertEquals ("#Clear2", "", + doc.DocumentElement.OuterXml); + AssertEquals ("#Clear3", "x", doc.DocumentElement.Prefix); + doc.DocumentElement.Prefix = newPrefix; + AssertEquals ("#Clear4", "", + doc.OuterXml); + AssertEquals ("#Clear5", "", + doc.DocumentElement.OuterXml); + AssertEquals ("#Clear6", string.Empty, doc.DocumentElement.Prefix); } } } diff --git a/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs b/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs index 4fd6f5586d8..90661afd68c 100644 --- a/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs +++ b/mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs @@ -1508,7 +1508,6 @@ namespace MonoTests.System.Xml } [Test] - [Category ("NotWorking")] [ExpectedException (typeof (ArgumentException))] public void WriteWhitespace_Null () { @@ -1516,7 +1515,6 @@ namespace MonoTests.System.Xml } [Test] - [Category ("NotWorking")] [ExpectedException (typeof (ArgumentException))] public void WriteWhitespace_Empty () { @@ -1524,7 +1522,6 @@ namespace MonoTests.System.Xml } [Test] - [Category ("NotWorking")] [ExpectedException (typeof (ArgumentException))] public void WriteNmToken_Null () { @@ -1532,7 +1529,6 @@ namespace MonoTests.System.Xml } [Test] - [Category ("NotWorking")] [ExpectedException (typeof (ArgumentException))] public void WriteNmToken_Empty () { -- cgit v1.2.3