Fix header collection from array (#18883)

* Fixed HeaderCollection::fromArray() key case

* Added CHANGELOG.md line for #18883 (Fixed HeaderCollection::fromArray() key case)
This commit is contained in:
rhertogh
2021-09-17 09:29:33 +02:00
committed by GitHub
parent 9ed87a0ad6
commit f3956a4eec
3 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -180,7 +180,7 @@ class HeaderCollection extends BaseObject implements \IteratorAggregate, \ArrayA
*/
public function fromArray(array $array)
{
$this->_headers = $array;
$this->_headers = array_change_key_case($array, CASE_LOWER);
}
/**

View File

@ -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'));
}
}