Skip to content

Commit

Permalink
Fixed yii\web\Request::getBodyParams() does not pass full 'content-…
Browse files Browse the repository at this point in the history
…type' value to `yii\web\RequestParserInterface::parse()`
  • Loading branch information
klimov-paul committed Sep 5, 2016
1 parent 487b2cb commit ed0603b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Yii Framework 2 Change Log
- Bug #11715: Fixed JS validation when the same model's attribute file input is listed more than once on the same page (uaoleg)
- Bug #11541: Fixed default MySQL integer display width for unsigned primary key (h311ion, rob006, cebe)
- Bug #12143: Fixed `yii\db\BaseActiveRecord::updateAttributes()` change `isNewRecord` state for the new model (klimov-paul)
- Bug #12463: Fixed `yii\web\Request::getBodyParams()` does not pass full 'content-type' value to `yii\web\RequestParserInterface::parse()` (klimov-paul)
- Enh #9708: Added `yii\console\controllers\AssetController::deleteSource` option allowing deletion of the source asset files after compression (pana1990, klimov-paul)
- Enh #10243: Added `yii\data\Sort::setAttributeOrders()` method allowing manual setup of current sort (klimov-paul)
- Enh #12440: Added `yii\base\Event::offAll()` method allowing clear all registered class-level event handlers (klimov-paul)
Expand Down
7 changes: 7 additions & 0 deletions framework/UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ php composer.phar global require "fxp/composer-asset-plugin:^1.2.0"
Upgrade from Yii 2.0.8
----------------------

* Method `yii\web\Request::getBodyParams()` has been changed to pass full value of 'content-type' header to the second
argument of `yii\web\RequestParserInterface::parse()`. If you create your own custom parser, which relies on `$contentType`
argument, ensure to process it correctly as it may content additional data.

Upgrade from Yii 2.0.8
----------------------

* Part of code from `yii\web\User::loginByCookie()` method was moved to new `getIdentityAndDurationFromCookie()`
and `removeIdentityCookie()` methods. If you override `loginByCookie()` method, update it in order use new methods.
* Fixture console command syntax was changed from `yii fixture "*" -User` to `yii fixture "*, -User"`. Upgrade your
Expand Down
12 changes: 7 additions & 5 deletions framework/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,24 +385,26 @@ public function getBodyParams()
return $this->_bodyParams;
}

$contentType = $this->getContentType();
if (($pos = strpos($contentType, ';')) !== false) {
$rawContentType = $this->getContentType();
if (($pos = strpos($rawContentType, ';')) !== false) {
// e.g. application/json; charset=UTF-8
$contentType = substr($contentType, 0, $pos);
$contentType = substr($rawContentType, 0, $pos);
} else {
$contentType = $rawContentType;
}

if (isset($this->parsers[$contentType])) {
$parser = Yii::createObject($this->parsers[$contentType]);
if (!($parser instanceof RequestParserInterface)) {
throw new InvalidConfigException("The '$contentType' request parser is invalid. It must implement the yii\\web\\RequestParserInterface.");
}
$this->_bodyParams = $parser->parse($this->getRawBody(), $contentType);
$this->_bodyParams = $parser->parse($this->getRawBody(), $rawContentType);
} elseif (isset($this->parsers['*'])) {
$parser = Yii::createObject($this->parsers['*']);
if (!($parser instanceof RequestParserInterface)) {
throw new InvalidConfigException("The fallback request parser is invalid. It must implement the yii\\web\\RequestParserInterface.");
}
$this->_bodyParams = $parser->parse($this->getRawBody(), $contentType);
$this->_bodyParams = $parser->parse($this->getRawBody(), $rawContentType);
} elseif ($this->getMethod() === 'POST') {
// PHP has already parsed the body so we have all params in $_POST
$this->_bodyParams = $_POST;
Expand Down

0 comments on commit ed0603b

Please sign in to comment.