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-01-05 23:16:41 +0300
committerGert Driesen <drieseng@users.sourceforge.net>2006-01-05 23:16:41 +0300
commitcd7644c9972bca5348cdabe1fc1870d65419737b (patch)
tree2437870b04fb461a9554ff5dba60ff1f0280ab81 /mcs/class/System.XML
parent2cde67007d2379f90ec0aa07ce7a0512ad0bffb6 (diff)
* 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
Diffstat (limited to 'mcs/class/System.XML')
-rw-r--r--mcs/class/System.XML/System.Xml/ChangeLog9
-rw-r--r--mcs/class/System.XML/System.Xml/XmlElement.cs9
-rw-r--r--mcs/class/System.XML/System.Xml/XmlTextWriter.cs61
-rw-r--r--mcs/class/System.XML/Test/System.Xml/ChangeLog8
-rw-r--r--mcs/class/System.XML/Test/System.Xml/XmlElementTests.cs30
-rw-r--r--mcs/class/System.XML/Test/System.Xml/XmlTextWriterTests.cs4
6 files changed, 86 insertions, 35 deletions
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 <drieseng@users.sourceforge.net>
+
+ * 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 <atsushi@ximian.com>
* 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 <drieseng@users.sourceforge.net>
+
+ * 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 <atsushi@ximian.com>
* 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 ("<root/>");
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 ("<root/>");
+ doc.LoadXml ("<root />");
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 ("<x:root xmlns:x=\"http://somenamespace.com\" />");
+ AssertEquals ("#Clear1", "<x:root xmlns:x=\"http://somenamespace.com\" />",
+ doc.OuterXml);
+ AssertEquals ("#Clear2", "<x:root xmlns:x=\"http://somenamespace.com\" />",
+ doc.DocumentElement.OuterXml);
+ AssertEquals ("#Clear3", "x", doc.DocumentElement.Prefix);
+ doc.DocumentElement.Prefix = newPrefix;
+ AssertEquals ("#Clear4", "<root xmlns:x=\"http://somenamespace.com\" xmlns=\"http://somenamespace.com\" />",
+ doc.OuterXml);
+ AssertEquals ("#Clear5", "<root xmlns:x=\"http://somenamespace.com\" xmlns=\"http://somenamespace.com\" />",
+ 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 ()
{