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

Commit d3e7fe3

Browse files
committed
Merge branch 'hotfix/51'
Close #51
2 parents 7406a79 + 84f8703 commit d3e7fe3

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ All notable changes to this project will be documented in this file, in reverse
2121

2222
### Fixed
2323

24-
- Nothing.
24+
- [#51](https://github.com/zendframework/zend-diactoros/pull/51) fixes
25+
`MessageTrait::getHeaderLine()` to return an empty string instead of `null` if
26+
the header is undefined (which is the behavior specified in PSR-7).
2527

2628
## 1.0.3 - 2015-06-04
2729

src/MessageTrait.php

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ public function getHeader($header)
142142
}
143143

144144
/**
145-
* Retrieves the line for a single header, with the header values as a
146-
* comma-separated string.
145+
* Retrieves a comma-separated string of the values for a single header.
147146
*
148147
* This method returns all of the header values of the given
149148
* case-insensitive header name as a string concatenated together using
@@ -154,18 +153,18 @@ public function getHeader($header)
154153
* and supply your own delimiter when concatenating.
155154
*
156155
* If the header does not appear in the message, this method MUST return
157-
* a null value.
156+
* an empty string.
158157
*
159-
* @param string $header Case-insensitive header field name.
160-
* @return string|null A string of values as provided for the given header
158+
* @param string $name Case-insensitive header field name.
159+
* @return string A string of values as provided for the given header
161160
* concatenated together using a comma. If the header does not appear in
162-
* the message, this method MUST return a null value.
161+
* the message, this method MUST return an empty string.
163162
*/
164-
public function getHeaderLine($header)
163+
public function getHeaderLine($name)
165164
{
166-
$value = $this->getHeader($header);
165+
$value = $this->getHeader($name);
167166
if (empty($value)) {
168-
return null;
167+
return '';
169168
}
170169

171170
return implode(',', $value);

test/MessageTraitTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,9 +198,9 @@ public function testGetHeaderReturnsAnEmptyArrayWhenHeaderDoesNotExist()
198198
$this->assertSame([], $this->message->getHeader('X-Foo-Bar'));
199199
}
200200

201-
public function testGetHeaderLineReturnsNullWhenHeaderDoesNotExist()
201+
public function testGetHeaderLineReturnsEmptyStringWhenHeaderDoesNotExist()
202202
{
203-
$this->assertNull($this->message->getHeaderLine('X-Foo-Bar'));
203+
$this->assertEmpty($this->message->getHeaderLine('X-Foo-Bar'));
204204
}
205205

206206
public function headersWithInjectionVectors()

test/RequestTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,19 +341,19 @@ public function testGetHostHeaderLineReturnsUriHostWhenPresent()
341341
/**
342342
* @group 39
343343
*/
344-
public function testGetHostHeaderLineReturnsNullIfNoUriPresent()
344+
public function testGetHostHeaderLineReturnsEmptyStringIfNoUriPresent()
345345
{
346346
$request = new Request();
347-
$this->assertNull($request->getHeaderLine('host'));
347+
$this->assertEmpty($request->getHeaderLine('host'));
348348
}
349349

350350
/**
351351
* @group 39
352352
*/
353-
public function testGetHostHeaderLineReturnsNullIfUriDoesNotContainHost()
353+
public function testGetHostHeaderLineReturnsEmptyStringIfUriDoesNotContainHost()
354354
{
355355
$request = new Request(new Uri());
356-
$this->assertNull($request->getHeaderLine('host'));
356+
$this->assertEmpty($request->getHeaderLine('host'));
357357
}
358358

359359
public function testPassingPreserveHostFlagWhenUpdatingUriDoesNotUpdateHostHeader()

0 commit comments

Comments
 (0)