public void TestProblem() { byte[] orig = Encoding.UTF8.GetBytes("<p><div>Hello<br>There!</div> <div>Tags!</div></p>"); byte[] fixed1 = Encoding.UTF8.GetBytes("<p><div>Hello<br/>There!</div> <div>Tags!</div></p>"); EvilUnclosedBRFixingInputStream inp = new EvilUnclosedBRFixingInputStream( new MemoryStream(orig) ); MemoryStream bout = new MemoryStream(); bool going = true; while (going) { byte[] b = new byte[1024]; int r = inp.Read(b); if (r > 0) { bout.Write(b, 0, r); } else { going = false; } } byte[] result = bout.ToArray(); Assert.IsTrue(Arrays.Equals(fixed1, result)); }
public void TestBufferSize() { byte[] orig = Encoding.UTF8.GetBytes("<p><div>Hello<br> <br>There!</div> <div>Tags!<br><br></div></p>"); byte[] fixed1 = Encoding.UTF8.GetBytes("<p><div>Hello<br/> <br/>There!</div> <div>Tags!<br/><br/></div></p>"); // Vary the buffer size, so that we can end up with the br in the // overflow or only part in the buffer for (int i = 5; i < orig.Length; i++) { EvilUnclosedBRFixingInputStream inp = new EvilUnclosedBRFixingInputStream( new MemoryStream(orig) ); MemoryStream bout = new MemoryStream(); bool going = true; while (going) { byte[] b = new byte[i]; int r = inp.Read(b); if (r > 0) { bout.Write(b, 0, r); } else { going = false; } } byte[] result = bout.ToArray(); Assert.IsTrue(Arrays.Equals(fixed1, result)); } }