Skip to content
This repository was archived by the owner on Jan 29, 2020. It is now read-only.

Commit 1727fd9

Browse files
committed
Merge branch 'hotfix/101'
Close #101 Fixes #100
2 parents c3b31a5 + a811f4e commit 1727fd9

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse
1818

1919
### Fixed
2020

21-
- Nothing.
21+
- [#101](https://github.com/zendframework/zend-diactoros/pull/101) fixes the
22+
`withHeader()` implementation to ensure that if the header existed previously
23+
but using a different casing strategy, the previous version will be removed
24+
in the cloned instance.
2225

2326
## 1.2.0 - 2015-11-24
2427

src/MessageTrait.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ public function withHeader($header, $value)
204204
$normalized = strtolower($header);
205205

206206
$new = clone $this;
207+
if ($new->hasHeader($header)) {
208+
unset($new->headers[$new->headerNames[$normalized]]);
209+
}
207210
$new->headerNames[$normalized] = $header;
208211
$new->headers[$header] = $value;
209212

test/MessageTraitTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ public function testWithHeaderRaisesExceptionForInvalidValueType($value)
175175
$message = $this->message->withHeader('X-Foo', $value);
176176
}
177177

178+
public function testWithHeaderReplacesDifferentCapitalization()
179+
{
180+
$this->message = $this->message->withHeader('X-Foo', ['foo']);
181+
$new = $this->message->withHeader('X-foo', ['bar']);
182+
$this->assertEquals(['bar'], $new->getHeader('x-foo'));
183+
$this->assertEquals(['X-foo' => ['bar']], $new->getHeaders());
184+
}
185+
178186
/**
179187
* @dataProvider invalidGeneralHeaderValues
180188
*/

0 commit comments

Comments
 (0)