Skip to content

Commit

Permalink
[HttpFoundation] Fix prepare request uri when it starts with double s…
Browse files Browse the repository at this point in the history
…lashes
  • Loading branch information
alquerci committed Dec 6, 2018
1 parent 317a2f9 commit 113a577
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Symfony/Component/HttpFoundation/Request.php
Expand Up @@ -1837,6 +1837,13 @@ protected function prepareRequestUri()
} elseif ($this->server->has('REQUEST_URI')) {
$requestUri = $this->server->get('REQUEST_URI');

// The REQUEST_URI starts with double slashes.
if (0 === strpos($requestUri, '//')) {
// We assume that the scheme and host are not provided (e.g. //path/too).
// Then patch the call to `parse_url()`.
$requestUri = "http://example.com$requestUri";
}

// HTTP proxy reqs setup request URI with scheme and host [and port] + the URL path, only use URL path
$uriComponents = parse_url($requestUri);

Expand Down
4 changes: 4 additions & 0 deletions src/Symfony/Component/HttpFoundation/Tests/RequestTest.php
Expand Up @@ -281,6 +281,10 @@ public function testCreateWithRequestUri()
$request = Request::create('http://test.com/foo#bar');
$request->server->set('REQUEST_URI', 'http://test.com/foo#bar');
$this->assertEquals('http://test.com/foo', $request->getUri());

$request = Request::create('http://foo//bar/foo');
$request->server->set('REQUEST_URI', '//bar/foo');
$this->assertEquals('//bar/foo', $request->getPathInfo(), 'When the REQUEST_URI starts with double slashes.');
}

public function testCreateCheckPrecedence()
Expand Down

0 comments on commit 113a577

Please sign in to comment.