download: fix invalid destructuring in range (fix #590)
Signed-off-by: Varun Patil <radialapps@gmail.com>pull/602/head
parent
6fb4b4dd23
commit
da192ee70e
|
@ -133,10 +133,10 @@ class DownloadController extends GenericApiController
|
|||
// check if http_range is sent by browser
|
||||
$range = $this->request->getHeader('Range');
|
||||
if (!empty($range)) {
|
||||
[$sizeUnit, $rangeOrig] = explode('=', $range, 2);
|
||||
[$sizeUnit, $rangeOrig] = Util::explode_exact('=', $range, 2);
|
||||
if ('bytes' === $sizeUnit) {
|
||||
// http://tools.ietf.org/id/draft-ietf-http-range-retrieval-00.txt
|
||||
[$range, $extra] = explode(',', $rangeOrig, 2);
|
||||
[$range, $extra] = Util::explode_exact(',', $rangeOrig, 2);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ class DownloadController extends GenericApiController
|
|||
|
||||
// Get file reading parameters
|
||||
$size = $file->getSize();
|
||||
[$seekStart, $seekEnd] = explode('-', $range, 2);
|
||||
[$seekStart, $seekEnd] = Util::explode_exact('-', $range, 2);
|
||||
$seekEnd = (empty($seekEnd)) ? ($size - 1) : min(abs((int) $seekEnd), $size - 1);
|
||||
$seekStart = (empty($seekStart) || $seekEnd < abs((int) $seekStart)) ? 0 : max(abs((int) $seekStart), 0);
|
||||
|
||||
|
|
14
lib/Util.php
14
lib/Util.php
|
@ -304,6 +304,20 @@ class Util
|
|||
return mb_ereg_replace('\/\/+', '/', $path); // remove extra slashes
|
||||
}
|
||||
|
||||
/**
|
||||
* Explode a string into fixed number of components.
|
||||
*
|
||||
* @param string $delimiter Delimiter
|
||||
* @param string $string String to explode
|
||||
* @param int $count Number of components
|
||||
*
|
||||
* @return string[] Array of components
|
||||
*/
|
||||
public static function explode_exact(string $delimiter, string $string, int $count): array
|
||||
{
|
||||
return array_pad(explode($delimiter, $string, $count), $count, '');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a system config key with the correct default.
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue