Skip to content

Commit

Permalink
fix(Core): fixes limit stream errors (#7117)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishwarajanand authored Mar 6, 2024
1 parent 76a2366 commit 0959c06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/Upload/ResumableUploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,13 @@ protected function getStatusResponse()
* Gets the starting range for the upload.
*
* @param string $rangeHeader
* @return int|null
* @return int
*/
protected function getRangeStart($rangeHeader)
{
if (!$rangeHeader) {
return null;
// assume no bytes are uploaded if no range header is present
return 0;
}

return (int) explode('-', $rangeHeader)[1] + 1;
Expand Down
27 changes: 27 additions & 0 deletions tests/Unit/Upload/ResumableUploaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,31 @@ public function testThrowsExceptionWithFailedUpload()

$uploader->upload();
}

/**
* @dataProvider rangeHeaderProvider
*/
public function testGetRangeStart($rangeHeader, $expectedRangeStart)
{
$method = new \ReflectionMethod(ResumableUploader::class, 'getRangeStart');
$method->setAccessible(true);

$uploader = $this->createMock(ResumableUploader::class);

$actualRangeStart = $method->invoke($uploader, $rangeHeader);
$this->assertEquals($expectedRangeStart, $actualRangeStart);
}

public function rangeHeaderProvider()
{
return
[
// range header, expected range start
['', 0],
['bytes 0-3/4', 4],
['bytes 0-99/100', 100],
['bytes 100-199/200', 200],
['bytes=2000-',1]
];
}
}

0 comments on commit 0959c06

Please sign in to comment.