Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0ddb310

Browse files
committed
[HttpFoundation] Fix prepare request uri when it starts with double slashes - KISS
1 parent113a577 commit0ddb310

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

‎src/Symfony/Component/HttpFoundation/Request.php‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,17 +1836,17 @@ protected function prepareRequestUri()
18361836
$this->server->remove('IIS_WasUrlRewritten');
18371837
}elseif ($this->server->has('REQUEST_URI')) {
18381838
$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);
18451848
}
18461849

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-
18501850
if (isset($uriComponents['path'])) {
18511851
$requestUri =$uriComponents['path'];
18521852
}

‎src/Symfony/Component/HttpFoundation/Tests/RequestTest.php‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,19 @@ public function testCreateWithRequestUri()
282282
$request->server->set('REQUEST_URI','http://test.com/foo#bar');
283283
$this->assertEquals('http://test.com/foo',$request->getUri());
284284

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
285290
$request = Request::create('http://foo//bar/foo');
286291
$request->server->set('REQUEST_URI','//bar/foo');
287292
$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.');
288298
}
289299

290300
publicfunctiontestCreateCheckPrecedence()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp