Skip to content

Commit

Permalink
WICKET-6058 Fixes error in calculation of byte ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Soloschenko authored and klopfdreh committed Dec 26, 2015
1 parent 7cd16b1 commit b5ee0cb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ public void writeData(Attributes attributes) throws IOException
{
// Stream is going to be read from the starting point next to the skipped bytes
// till the end byte computed by the range between startbyte / endbyte
boundedInputStream = new BoundedInputStream(inputStream, endbyte - startbyte);
boundedInputStream = new BoundedInputStream(inputStream,
(endbyte - startbyte) + 1);

// The original input stream is going to be closed by the end of the request
// so set propagate close to false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,8 @@ public void testCSSResourceReferenceRespectsMinifiedResourcesDetection()
public void testContentRange()
{
// Test range
Assert.assertEquals("resource", makeRangeRequest("bytes=0-8"));
Assert.assertEquals("ource", makeRangeRequest("bytes=3-8"));
Assert.assertEquals("resource", makeRangeRequest("bytes=0-7"));
Assert.assertEquals("ource", makeRangeRequest("bytes=3-7"));
Assert.assertEquals("resource_var_style_en.txt", makeRangeRequest("bytes=0-"));
Assert.assertEquals("var_style_en.txt", makeRangeRequest("bytes=9-"));
Assert.assertEquals("resource_var_style_en.txt", makeRangeRequest("bytes=-"));
Expand Down Expand Up @@ -292,14 +292,14 @@ public void testContentRangeLarge() throws IOException
String content = new String(IOUtils.toByteArray(resourceAsStream));

// Check buffer comprehensive range request
String bytes4094_4106 = makeRangeRequestToBigResource("bytes=4094-4106");
assertEquals(12, bytes4094_4106.length());
assertEquals("River Roller", bytes4094_4106);
String bytes4094_4105 = makeRangeRequestToBigResource("bytes=4094-4105");
assertEquals(12, bytes4094_4105.length());
assertEquals("River Roller", bytes4094_4105);

// Check buffer exceeding range request
String bytes1000_5000 = makeRangeRequestToBigResource("bytes=1000-5000");
assertEquals(4000, bytes1000_5000.length());
assertEquals(content.substring(1000, 5000), bytes1000_5000);
String bytes1000_4999 = makeRangeRequestToBigResource("bytes=1000-4999");
assertEquals(4000, bytes1000_4999.length());
assertEquals(content.substring(1000, 5000), bytes1000_4999);

// Check buffer exceeding range request until end of content
String bytes1000_end = makeRangeRequestToBigResource("bytes=1000-");
Expand Down

0 comments on commit b5ee0cb

Please sign in to comment.