Permalink
Browse files

Fix bug (introduced by super-fast-parser work) where a rendering pipe…

…line involving FastParser.parse(char[], int) would result in a content-length being a power of 2, and the trailing bytes all being 0.

This fixes JRA-24760.
  • Loading branch information...
1 parent 147284a commit f8b0a6e97c96c6f068259a9888fe4b8d4b762681 @spudbean spudbean committed Jun 6, 2011
@@ -68,8 +68,14 @@ private void addAttributeList(String prefix, Map attributes)
}
}
- public void setVerbatimPage(char[] v)
+ public void setVerbatimPage(char[] v, int length)
{
+ if (v.length > length) {
+ // todo fix this parser so that it doesn't need to compact the array
+ char[] newData = new char[length];
+ System.arraycopy(v, 0, newData, 0, length);
+ v = newData;
+ }
this.pageData = v;
}
@@ -91,7 +91,7 @@ public Page parse(char[] data) throws IOException
public Page parse(char[] data, int length) throws IOException
{
FastPage page = internalParse(new CharArrayReader(data, 0, length));
- page.setVerbatimPage(data);
+ page.setVerbatimPage(data, length);
return page;
}
@@ -56,6 +56,7 @@ public static Test suite() throws Exception {
suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testHead"));
suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testFullPage"));
suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testProperties"));
+ suiteForFile.addTest(new HTMLPageParserTest(parser, file, "testContentSanity"));
suiteForParser.addTest(suiteForFile);
}
result.addTest(suiteForParser);
@@ -137,6 +138,20 @@ public void testProperties() throws Exception {
}
}
+ /**
+ * compare difference between using parse(char[]) and parse(char[], length)
+ */
+ public void testContentSanity() throws Exception {
+ String input = (String) blocks.get("INPUT");
+ final char[] chars = input.toCharArray();
+ final char[] bigChars = new char[chars.length * 2 + 10]; // make it bigger
+ System.arraycopy(chars, 0, bigChars, 0, chars.length);
+ Page bigPage = parser.parse(bigChars, chars.length);
+
+ assertEquals(bigPage.getPage(), page.getPage());
+ assertEquals(bigPage.getContentLength(), page.getContentLength());
+ }
+
private String join(String[] values) {
StringBuffer result = new StringBuffer();
for (int i = 0; i < values.length; i++) {

0 comments on commit f8b0a6e

Please sign in to comment.