Parcourir la source

2009-01-20 Atsushi Enomoto <[email protected]>

	* XmlReaderBinarySupport.cs : do not hang in the middle of reading
	  byte chunk at some node types. Fixed bug #464229.

	* XmlReaderCommonTests.cs : added test for bug #464229.


svn path=/trunk/mcs/; revision=123866
Atsushi Eno il y a 17 ans
Parent
commit
aa2607300a

+ 5 - 0
mcs/class/System.XML/System.Xml/ChangeLog

@@ -1,3 +1,8 @@
+2009-01-20  Atsushi Enomoto  <[email protected]>
+
+	* XmlReaderBinarySupport.cs : do not hang in the middle of reading
+	  byte chunk at some node types. Fixed bug #464229.
+
 2009-01-14  Sebastien Pouliot  <[email protected]>
 2009-01-14  Sebastien Pouliot  <[email protected]>
 
 
 	* NamespaceHandling.cs: New. Enum for Silverlight 2. Microsoft's 
 	* NamespaceHandling.cs: New. Enum for Silverlight 2. Microsoft's 

+ 7 - 4
mcs/class/System.XML/System.Xml/XmlReaderBinarySupport.cs

@@ -354,8 +354,8 @@ namespace System.Xml
 					return 0;
 					return 0;
 			}
 			}
 
 
-			bool consumeToEnd = false;
-			while (!consumeToEnd && textCache.Length < length) {
+			bool loop = true;
+			while (loop && textCache.Length < length) {
 				switch (reader.NodeType) {
 				switch (reader.NodeType) {
 				case XmlNodeType.Text:
 				case XmlNodeType.Text:
 				case XmlNodeType.CDATA:
 				case XmlNodeType.CDATA:
@@ -370,13 +370,16 @@ namespace System.Xml
 							Read ();
 							Read ();
 							break;
 							break;
 						default:
 						default:
-							consumeToEnd = true;
+							loop = false;
 							break;
 							break;
 						}
 						}
 					}
 					}
 					textCache.Append (reader.Value);
 					textCache.Append (reader.Value);
 					hasCache = true;
 					hasCache = true;
 					break;
 					break;
+				default:
+					loop = false;
+					break;
 				}
 				}
 			}
 			}
 			state = backup;
 			state = backup;
@@ -386,7 +389,7 @@ namespace System.Xml
 			string str = textCache.ToString (0, min);
 			string str = textCache.ToString (0, min);
 			textCache.Remove (0, str.Length);
 			textCache.Remove (0, str.Length);
 			str.CopyTo (0, buffer, offset, str.Length);
 			str.CopyTo (0, buffer, offset, str.Length);
-			if (min < length)
+			if (min < length && loop)
 				return min + ReadValueChunk (buffer, offset + min, length - min);
 				return min + ReadValueChunk (buffer, offset + min, length - min);
 			else
 			else
 				return min;
 				return min;

+ 4 - 0
mcs/class/System.XML/Test/System.Xml/ChangeLog

@@ -1,3 +1,7 @@
+2009-01-20  Atsushi Enomoto  <[email protected]>
+
+	* XmlReaderCommonTests.cs : added test for bug #464229.
+
 2009-01-08  Atsushi Enomoto  <[email protected]>
 2009-01-08  Atsushi Enomoto  <[email protected]>
 
 
 	* XmlReaderCommonTests.cs : added test for ReadContentAsString()
 	* XmlReaderCommonTests.cs : added test for ReadContentAsString()

+ 27 - 0
mcs/class/System.XML/Test/System.Xml/XmlReaderCommonTests.cs

@@ -2103,6 +2103,7 @@ namespace MonoTests.System.Xml
 			r.ReadSubtree ();
 			r.ReadSubtree ();
 		}
 		}
 
 
+		[Test]
 		public void ReadSubtreeEmptyElement ()
 		public void ReadSubtreeEmptyElement ()
 		{
 		{
 			string xml = @"<x/>";
 			string xml = @"<x/>";
@@ -2115,6 +2116,7 @@ namespace MonoTests.System.Xml
 			AssertEquals ("#4", XmlNodeType.None, s.NodeType);
 			AssertEquals ("#4", XmlNodeType.None, s.NodeType);
 		}
 		}
 
 
+		[Test]
 		public void ReadSubtreeEmptyElementWithAttribute ()
 		public void ReadSubtreeEmptyElementWithAttribute ()
 		{
 		{
 			string xml = @"<root><x a='b'/></root>";
 			string xml = @"<root><x a='b'/></root>";
@@ -2135,6 +2137,31 @@ namespace MonoTests.System.Xml
 			Assert ("#5", r.IsEmptyElement);
 			Assert ("#5", r.IsEmptyElement);
 			Assert ("#6", r2.IsEmptyElement);
 			Assert ("#6", r2.IsEmptyElement);
 		}
 		}
+
+		[Test]
+		public void ReadContentAsBase64 ()
+		{
+			byte[] randomData = new byte[24];
+			for (int i = 0; i < randomData.Length; i++)
+				randomData [i] = (byte) i;
+
+			string xmlString = "<?xml version=\"1.0\"?><data>" +
+			Convert.ToBase64String (randomData) + "</data>";
+			TextReader textReader = new StringReader (xmlString);
+			XmlReader xmlReader = XmlReader.Create (textReader);
+			xmlReader.ReadToFollowing ("data");
+
+			int readBytes = 0;
+			byte[] buffer = new byte [24];
+
+			xmlReader.ReadStartElement ();
+			readBytes = xmlReader.ReadContentAsBase64 (buffer, 0, buffer.Length);
+			AssertEquals ("#1", 24, readBytes);
+			AssertEquals ("#2", 0, xmlReader.ReadContentAsBase64 (buffer, 0, buffer.Length));
+			StringWriter sw = new StringWriter ();
+			foreach (byte b in buffer) sw.Write ("{0:X02}", b);
+			AssertEquals ("#3", "000102030405060708090A0B0C0D0E0F1011121314151617", sw.ToString ());
+		}
 #endif
 #endif
 	}
 	}
 }
 }