10000 merged branch Tobion/headerbag (PR #5282) · symfony/symfony@d3625b0 · GitHub
[go: up one dir, main page]

Skip to content

Commit d3625b0

Browse files
committed
merged branch Tobion/headerbag (PR #5282)
Commits ------- ccb6dad [HttpFoundation] fixed undefined offset for assoc arrays in HeaderBag Discussion ---------- [HttpFoundation] fixed undefined offset for assoc arrays in HeaderBag `get` is assuming the headers are zero-indexed. So something like this would otherwise create a php warning. ``` $bag->set('foo', array('bad-assoc-index' => 'value')); $this->assertSame('value', $bag->get('foo')); ```
2 parents 71d2301 + ccb6dad commit d3625b0

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/Symfony/Component/HttpFoundation/HeaderBag.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function set($key, $values, $replace = true)
157157
{
158158
$key = strtr(strtolower($key), '_', '-');
159159

160-
$values = (array) $values;
160+
$values = array_values((array) $values);
161161

162162
if (true === $replace || !isset($this->headers[$key])) {
163163
$this->headers[$key] = $values;

src/Symfony/Component/HttpFoundation/Tests/HeaderBagTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ public function testGet()
6868
$this->assertEquals( array('bar', 'bor'), $bag->get('foo', 'nope', false), '->get return all values as array');
6969
}
7070

71+
public function testSetAssociativeArray()
72+
{
73+
$bag = new HeaderBag();
74+
$bag->set('foo', array('bad-assoc-index' => 'value'));
75+
$this->assertSame('value', $bag->get('foo'));
76+
$this->assertEquals(array('value'), $bag->get('foo', 'nope', false), 'assoc indices of multi-valued headers are ignored');
77+
}
78+
7179
/**
7280
* @covers Symfony\Component\HttpFoundation\HeaderBag::contains
7381
*/

0 commit comments

Comments
 (0)
0