Browse Source

Fix header collection from array (#18883)

* Fixed HeaderCollection::fromArray() key case

* Added CHANGELOG.md line for #18883 (Fixed HeaderCollection::fromArray() key case)
tags/2.0.44
rhertogh 3 years ago committed by GitHub
parent
commit
f3956a4eec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      framework/CHANGELOG.md
  2. 2
      framework/web/HeaderCollection.php
  3. 27
      tests/framework/web/HeaderCollectionTest.php

1
framework/CHANGELOG.md

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

2
framework/web/HeaderCollection.php

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

27
tests/framework/web/HeaderCollectionTest.php

@ -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'));
}
}
Loading…
Cancel
Save