File tree Expand file tree Collapse file tree 2 files changed +19
-9
lines changed
src/Symfony/Component/HttpFoundation Expand file tree Collapse file tree 2 files changed +19
-9
lines changed Original file line number Diff line number Diff line change @@ -1836,17 +1836,17 @@ protected function prepareRequestUri()
1836
1836
$ this ->server ->remove ('IIS_WasUrlRewritten ' );
1837
1837
} elseif ($ this ->server ->has ('REQUEST_URI ' )) {
1838
1838
$ requestUri = $ this ->server ->get ('REQUEST_URI ' );
1839
-
1840
- // The REQUEST_URI starts with double slashes.
1841
- if (0 === strpos ($ requestUri , '// ' )) {
1842
- // We assume that the scheme and host are not provided (e.g. //path/too).
1843
- // Then patch the call to `parse_url()`.
1844
- $ requestUri = "http://example.com $ requestUri " ;
1839
+ $ uriComponents = array ();
1840
+
1841
+ // HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path,
1842
+ // only use URL path.
1843
+ if ('' !== $ requestUri && '/ ' !== $ requestUri [0 ]) {
1844
+ $ uriComponents = parse_url ($ requestUri );
1845
+ } elseif (false !== $ pos = strpos ($ requestUri , '# ' )) {
1846
+ // Remove the fragment.
1847
+ $ requestUri = substr ($ requestUri , 0 , $ pos );
1845
1848
}
1846
1849
1847
- // HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path, only use URL path
1848
- $ uriComponents = parse_url ($ requestUri );
1849
-
1850
1850
if (isset ($ uriComponents ['path ' ])) {
1851
1851
$ requestUri = $ uriComponents ['path ' ];
1852
1852
}
Original file line number Diff line number Diff line change @@ -282,9 +282,19 @@ public function testCreateWithRequestUri()
282
282
$ request ->server ->set ('REQUEST_URI ' , 'http://test.com/foo#bar ' );
283
283
$ this ->assertEquals ('http://test.com/foo ' , $ request ->getUri ());
284
284
285
+ $ request = Request::create ('http://test.com/foo#bar ' );
286
+ $ request ->server ->set ('REQUEST_URI ' , '/foo#bar ' );
287
+ $ this ->assertEquals ('http://test.com/foo ' , $ request ->getUri ());
288
+
289
+ // When the path starts with 2 slashes
285
290
$ request = Request::create ('http://foo//bar/foo ' );
286
291
$ request ->server ->set ('REQUEST_URI ' , '//bar/foo ' );
287
292
$ this ->assertEquals ('//bar/foo ' , $ request ->getPathInfo (), 'When the REQUEST_URI starts with double slashes. ' );
293
+
294
+ // When the path starts with more than 2 slashes
295
+ $ request = Request::create ('http://foo///bar/foo ' );
296
+ $ request ->server ->set ('REQUEST_URI ' , '///bar/foo ' );
297
+ $ this ->assertEquals ('///bar/foo ' , $ request ->getPathInfo (), 'When the REQUEST_URI starts with more than 2 slashes. ' );
288
298
}
289
299
290
300
public function testCreateCheckPrecedence ()
You can’t perform that action at this time.
0 commit comments