Skip to content

Commit

Permalink
Enhanced 9f499eb: yii\web\User::checkRedirectAcceptable() removed c…
Browse files Browse the repository at this point in the history
…heck for "*" type (invalid in accept header)
  • Loading branch information
SilverFire committed May 15, 2016
1 parent b976f63 commit 0ff6eeb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
4 changes: 2 additions & 2 deletions framework/web/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -697,12 +697,12 @@ public function can($permissionName, $params = [], $allowCaching = true)
protected function checkRedirectAcceptable()
{
$acceptableTypes = Yii::$app->getRequest()->getAcceptableContentTypes();
if (empty($acceptableTypes)) {
if (empty($acceptableTypes) || count($acceptableTypes) === 1 && array_keys($acceptableTypes)[0] === '*/*') {
return true;
}

foreach ($acceptableTypes as $type => $params) {
if ($type === '*' || $type === '*/*' || in_array($type, $this->acceptableRedirectTypes, true)) {
if (in_array($type, $this->acceptableRedirectTypes, true)) {
return true;
}
}
Expand Down
13 changes: 7 additions & 6 deletions tests/framework/web/UserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,17 +210,18 @@ public function testLoginRequired()

$this->reset();
Yii::$app->request->setUrl('accept-all');
$_SERVER['HTTP_ACCEPT'] = '*;q=0.1';
$_SERVER['HTTP_ACCEPT'] = '*/*;q=0.1';
$user->loginRequired();
$this->assertEquals('accept-all', $user->getReturnUrl());
$this->assertTrue(Yii::$app->response->getIsRedirection());

$this->reset();
Yii::$app->request->setUrl('accept-all');
$_SERVER['HTTP_ACCEPT'] = '*/*;q=0.1';
$user->loginRequired();
$this->assertEquals('accept-all', $user->getReturnUrl());
$this->assertTrue(Yii::$app->response->getIsRedirection());
Yii::$app->request->setUrl('json-and-accept-all');
$_SERVER['HTTP_ACCEPT'] = 'text/json, */*; q=0.1';
try {
$user->loginRequired();
} catch (ForbiddenHttpException $e) {}
$this->assertFalse(Yii::$app->response->getIsRedirection());

$this->reset();
Yii::$app->request->setUrl('accept-html-json');
Expand Down

0 comments on commit 0ff6eeb

Please sign in to comment.