Skip to content

Commit

Permalink
Fix header collection from array (#18883)
Browse files Browse the repository at this point in the history
* Fixed HeaderCollection::fromArray() key case

* Added CHANGELOG.md line for #18883 (Fixed HeaderCollection::fromArray() key case)
  • Loading branch information
rhertogh committed Sep 17, 2021
1 parent 9ed87a0 commit f3956a4
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions framework/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Yii Framework 2 Change Log
- Bug #18842: Fix `yii\base\Controller::bindInjectedParams()` to not throw error when argument of `ReflectionUnionType` type is passed (bizley)
- Enh #18858: Reduce memory usage in `yii\base\View::afterRender` method (LeoOnTheEarth)
- Bug #18880: Fix `yii\helpers\ArrayHelper::toArray()` for `DateTime` objects in PHP >= 7.4 (rhertogh)
- Bug #18883: Fix `yii\web\HeaderCollection::fromArray()` now ensures lower case keys (rhertogh)


2.0.43 August 09, 2021
Expand Down
2 changes: 1 addition & 1 deletion framework/web/HeaderCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public function toArray()
*/
public function fromArray(array $array)
{
$this->_headers = $array;
$this->_headers = array_change_key_case($array, CASE_LOWER);
}

/**
Expand Down
27 changes: 27 additions & 0 deletions tests/framework/web/HeaderCollectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/

namespace yiiunit\framework\web;

use yii\web\HeaderCollection;
use yiiunit\TestCase;

/**
* @group web
*/
class HeaderCollectionTest extends TestCase
{
public function testFromArray()
{
$headerCollection = new HeaderCollection();
$location = 'my-test-location';
$headerCollection->fromArray([
'Location' => [$location],
]);
$this->assertEquals($location, $headerCollection->get('Location'));
}
}

0 comments on commit f3956a4

Please sign in to comment.