diff --git a/plist-cil.test/PropertyListParserTests.cs b/plist-cil.test/PropertyListParserTests.cs new file mode 100644 index 0000000..02a06c3 --- /dev/null +++ b/plist-cil.test/PropertyListParserTests.cs @@ -0,0 +1,20 @@ +using Claunia.PropertyList; +using NUnit.Framework; +using System.IO; + +namespace plistcil.test +{ + [TestFixture] + public class PropertyListParserTests + { + [Test] + [ExpectedException(typeof(PropertyListFormatException))] + public static void ParseEmptyStreamTest() + { + using (MemoryStream stream = new MemoryStream()) + { + PropertyListParser.Parse(stream); + } + } + } +} diff --git a/plist-cil.test/plist-cil.test.csproj b/plist-cil.test/plist-cil.test.csproj index 5cc1427..52b15f1 100644 --- a/plist-cil.test/plist-cil.test.csproj +++ b/plist-cil.test/plist-cil.test.csproj @@ -40,6 +40,7 @@ + diff --git a/plist-cil/PropertyListParser.cs b/plist-cil/PropertyListParser.cs index 93e6d62..e2ca66e 100644 --- a/plist-cil/PropertyListParser.cs +++ b/plist-cil/PropertyListParser.cs @@ -81,7 +81,7 @@ namespace Claunia.PropertyList //Skip Unicode byte order mark (BOM) offset += 3; } - while (offset < bytes.Length && bytes[offset] == ' ' || bytes[offset] == '\t' || bytes[offset] == '\r' || bytes[offset] == '\n' || bytes[offset] == '\f') + while (offset < bytes.Length && (bytes[offset] == ' ' || bytes[offset] == '\t' || bytes[offset] == '\r' || bytes[offset] == '\n' || bytes[offset] == '\f')) { offset++; } @@ -129,16 +129,11 @@ namespace Claunia.PropertyList /// The Stream pointing to the data that should be stored in the array. internal static byte[] ReadAll(Stream fs) { - MemoryStream outputStream = new MemoryStream(); - byte[] buf = new byte[512]; - int read = 512; - while (read == 512) + using (MemoryStream outputStream = new MemoryStream()) { - read = fs.Read(buf, 0, 512); - if (read != -1) - outputStream.Write(buf, 0, read); + fs.CopyTo(outputStream); + return outputStream.ToArray(); } - return outputStream.ToArray(); } ///