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

Commit 9ad7add

Browse files
committed
Merge branch 'hotfix/132'
Close #132
2 parents d25487d + 81a1c36 commit 9ad7add

File tree

3 files changed

+24
-0
lines changed

3 files changed

+24
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ All notable changes to this project will be documented in this file, in reverse
2323
validation of the HTTP protocol version.
2424
- [#127](https://github.com/zendframework/zend-diactoros/pull/127) now properly
2525
removes attributes with `null` values when calling `withoutAttribute()`.
26+
- [#132](https://github.com/zendframework/zend-diactoros/pull/132) updates the
27+
`ServerRequestFactory` to marshal the request path fragment, if present.
2628

2729
## 1.3.3 - 2016-01-04
2830

src/ServerRequestFactory.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,15 @@ public static function marshalUriFromServer(array $server, array $headers)
262262
$query = ltrim($server['QUERY_STRING'], '?');
263263
}
264264

265+
// URI fragment
266+
$fragment = '';
267+
if (strpos($path, '#') !== false) {
268+
list($path, $fragment) = explode('#', $path, 2);
269+
}
270+
265271
return $uri
266272
->withPath($path)
273+
->withFragment($fragment)
267274
->withQuery($query);
268275
}
269276

test/ServerRequestFactoryTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,21 @@ public function testMarshalUriInjectsQueryStringFromServer()
339339
$this->assertEquals('bar=baz', $uri->getQuery());
340340
}
341341

342+
public function testMarshalUriInjectsFragmentFromServer()
343+
{
344+
$request = new ServerRequest();
345+
$request = $request->withUri(new Uri('http://example.com/'));
346+
$request = $request->withHeader('Host', 'example.com');
347+
348+
$server = [
349+
'REQUEST_URI' => '/foo/bar#foo',
350+
];
351+
352+
$uri = ServerRequestFactory::marshalUriFromServer($server, $request->getHeaders());
353+
$this->assertInstanceOf('Zend\Diactoros\Uri', $uri);
354+
$this->assertEquals('foo', $uri->getFragment());
355+
}
356+
342357
public function testCanCreateServerRequestViaFromGlobalsMethod()
343358
{
344359
$server = [

0 commit comments

Comments
 (0)