mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 04:37:42 +08:00
Fix #18789: Added JSONP support in yii\web\JsonParser::parse()
This commit is contained in:
@ -21,6 +21,7 @@ Yii Framework 2 Change Log
|
||||
- Enh #18734: Added `yii\validators\EmailValidator::$enableLocalIDN` (brandonkelly)
|
||||
- Bug #18756: Fix `\yii\validators\ExistValidator::queryValueExists` to validate against an array of unique values (DrDeath72)
|
||||
- Enh #18656: Added ability for `yii serve`'s `--router` param to take an alias (markhuot)
|
||||
- Enh #18789: Added JSONP support in `yii\web\JsonParser::parse()` (WinterSilence)
|
||||
- Bug #18274: Fix `yii\log\Logger` to calculate profile timings no matter the value of the flush interval (bizley)
|
||||
|
||||
|
||||
|
||||
@ -33,7 +33,7 @@ class JsonParser implements RequestParserInterface
|
||||
*/
|
||||
public $asArray = true;
|
||||
/**
|
||||
* @var bool whether to throw a [[BadRequestHttpException]] if the body is invalid json
|
||||
* @var bool whether to throw a [[BadRequestHttpException]] if the body is invalid JSON
|
||||
*/
|
||||
public $throwException = true;
|
||||
|
||||
@ -42,11 +42,16 @@ class JsonParser implements RequestParserInterface
|
||||
* Parses a HTTP request body.
|
||||
* @param string $rawBody the raw HTTP request body.
|
||||
* @param string $contentType the content type specified for the request body.
|
||||
* @return array parameters parsed from the request body
|
||||
* @return array|\stdClass parameters parsed from the request body
|
||||
* @throws BadRequestHttpException if the body contains invalid json and [[throwException]] is `true`.
|
||||
*/
|
||||
public function parse($rawBody, $contentType)
|
||||
{
|
||||
// converts JSONP to JSON
|
||||
if (strpos($contentType, 'application/javascript') !== false) {
|
||||
$rawBody = preg_filter('/(^[^{]+|[^}]+$)/', '', $rawBody);
|
||||
}
|
||||
|
||||
try {
|
||||
$parameters = Json::decode($rawBody, $this->asArray);
|
||||
return $parameters === null ? [] : $parameters;
|
||||
|
||||
Reference in New Issue
Block a user