From 1f3f66129291f41f1161d8b20802aaba6c9fd194 Mon Sep 17 00:00:00 2001 From: Ragazzo Date: Thu, 16 May 2013 17:47:22 +0400 Subject: [PATCH 1/4] fixed range requests, tests improved --- tests/unit/framework/web/ResponseTest.php | 32 +++++++++++++++++++++++++++---- yii/web/Response.php | 10 +++++++--- 2 files changed, 35 insertions(+), 7 deletions(-) diff --git a/tests/unit/framework/web/ResponseTest.php b/tests/unit/framework/web/ResponseTest.php index b3d9080..2fde63d 100644 --- a/tests/unit/framework/web/ResponseTest.php +++ b/tests/unit/framework/web/ResponseTest.php @@ -41,7 +41,7 @@ class ResponseTest extends \yiiunit\TestCase static::$httpResponseCode = 200; } - public function ranges() + public function rightRanges() { // TODO test more cases for range requests and check for rfc compatibility // http://www.w3.org/Protocols/rfc2616/rfc2616.txt @@ -53,14 +53,14 @@ class ResponseTest extends \yiiunit\TestCase } /** - * @dataProvider ranges + * @dataProvider rightRanges */ public function testSendFileRanges($rangeHeader, $expectedHeader, $length, $expectedFile) { $content = $this->generateTestFileContent(); - $_SERVER['HTTP_RANGE'] = 'bytes=' . $rangeHeader; $sent = $this->runSendFile('testFile.txt', $content, null); + $this->assertEquals($expectedFile, $sent); $this->assertTrue(in_array('HTTP/1.1 206 Partial Content', static::$headers)); $this->assertTrue(in_array('Accept-Ranges: bytes', static::$headers)); @@ -69,6 +69,30 @@ class ResponseTest extends \yiiunit\TestCase $this->assertTrue(in_array('Content-Length: ' . $length, static::$headers)); } + public function wrongRanges() + { + // TODO test more cases for range requests and check for rfc compatibility + // http://www.w3.org/Protocols/rfc2616/rfc2616.txt + return array( + array('1-2,3-5,6-10'), // multiple range request not supported + array('5-1'), // last-byte-pos value is less than its first-byte-pos value + array('-100000'), // last-byte-pos bigger then content length + array('10000-'), // first-byte-pos bigger then content length + ); + } + + /** + * @dataProvider wrongRanges + */ + public function testSendFileWrongRanges($rangeHeader) + { + $this->setExpectedException('yii\base\HttpException', 'Requested Range Not Satisfiable'); + + $content = $this->generateTestFileContent(); + $_SERVER['HTTP_RANGE'] = 'bytes=' . $rangeHeader; + $this->runSendFile('testFile.txt', $content, null); + } + protected function generateTestFileContent() { return '12ёжик3456798áèabcdefghijklmnopqrstuvwxyz!"§$%&/(ёжик)=?'; @@ -83,4 +107,4 @@ class ResponseTest extends \yiiunit\TestCase $file = ob_get_clean(); return $file; } -} \ No newline at end of file +} diff --git a/yii/web/Response.php b/yii/web/Response.php index 954c999..3140c54 100644 --- a/yii/web/Response.php +++ b/yii/web/Response.php @@ -50,7 +50,7 @@ class Response extends \yii\base\Response if (isset($_SERVER['HTTP_RANGE'])) { // client sent us a multibyte range, can not hold this one for now - if (strpos(',', $_SERVER['HTTP_RANGE']) !== false) { + if (strpos($_SERVER['HTTP_RANGE'],',') !== false) { header("Content-Range: bytes $contentStart-$contentEnd/$fileSize"); throw new HttpException(416, 'Requested Range Not Satisfiable'); } @@ -63,14 +63,18 @@ class Response extends \yii\base\Response } else { $range = explode('-', $range); $contentStart = $range[0]; - $contentEnd = (isset($range[1]) && is_numeric($range[1])) ? $range[1] : $fileSize - 1; + + // check if the last-byte-pos presents in header + if ((isset($range[1]) && is_numeric($range[1]))) { + $contentEnd = $range[1]; + } } /* Check the range and make sure it's treated according to the specs. * http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html */ // End bytes can not be larger than $end. - $contentEnd = ($contentEnd > $fileSize) ? $fileSize : $contentEnd; + $contentEnd = ($contentEnd > $fileSize) ? $fileSize -1 : $contentEnd; // Validate the requested range and return an error if it's not correct. $wrongContentStart = ($contentStart > $contentEnd || $contentStart > $fileSize - 1 || $contentStart < 0); From d07db994686975f4052fe6bf771b8c6ab92d667b Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 20 May 2013 21:15:55 +0400 Subject: [PATCH 2/4] "vendor-dir": "vendor" is default, removed --- apps/bootstrap/composer.json | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/bootstrap/composer.json b/apps/bootstrap/composer.json index 86e399b..b2300b2 100644 --- a/apps/bootstrap/composer.json +++ b/apps/bootstrap/composer.json @@ -12,9 +12,6 @@ "irc": "irc://irc.freenode.net/yii", "source": "https://github.com/yiisoft/yii2" }, - "config": { - "vendor-dir": "vendor" - }, "minimum-stability": "dev", "require": { "php": ">=5.3.0", From a856ddb613cb5a0070c583bc4d6d3f0f36ef7808 Mon Sep 17 00:00:00 2001 From: Alexander Makarov Date: Mon, 20 May 2013 21:37:14 +0400 Subject: [PATCH 3/4] moved optional packages to "suggest", updated platform requirements --- yii/composer.json | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/yii/composer.json b/yii/composer.json index eb4c734..c8c0dd3 100644 --- a/yii/composer.json +++ b/yii/composer.json @@ -64,10 +64,14 @@ "source": "https://github.com/yiisoft/yii2" }, "require": { - "php": ">=5.3.0", - "michelf/php-markdown": "1.3", - "twig/twig": "1.12.*", - "smarty/smarty": "3.1.*", - "ezyang/htmlpurifier": "v4.5.0" + "php": ">=5.3.11", + "ext-mbstring": "*", + "lib-pcre": "*" + }, + "suggest": { + "michelf/php-markdown": "Required for Markdown helper.", + "twig/twig": "Required for TwigViewRenderer.", + "smarty/smarty": "Required for SmartyViewRenderer.", + "ezyang/htmlpurifier": "Required for Purifier helper." } } From cb22fd9c64b163f4642e2a9e2fcbff87abf37949 Mon Sep 17 00:00:00 2001 From: Klimov Paul Date: Mon, 20 May 2013 20:37:19 +0300 Subject: [PATCH 4/4] PHP Intl extension has been added to default Yii requirements. --- yii/requirements/requirements.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/yii/requirements/requirements.php b/yii/requirements/requirements.php index a703fde..125ff60 100644 --- a/yii/requirements/requirements.php +++ b/yii/requirements/requirements.php @@ -2,6 +2,8 @@ /** * This is the Yii core requirements for the [[YiiRequirementChecker]] instance. * These requirements are mandatory for any Yii application. + * + * @var $this YiiRequirementChecker */ return array( array( @@ -36,4 +38,11 @@ return array( 'by' => 'Multibyte string processing', 'memo' => 'Required for multibyte encoding string processing.' ), + array( + 'name' => 'Intl extension', + 'mandatory' => true, + 'condition' => $this->checkPhpExtensionVersion('intl', '1.0.2'), + 'by' => 'Internationalization support', + 'memo' => 'PHP Intl extension 1.0.2 or higher is required.' + ), ); \ No newline at end of file