Skip to content

Commit

Permalink
Work around parse_url() bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Sep 11, 2024
1 parent 9c375b2 commit b61630e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,11 @@ public static function create(string $uri, string $method = 'GET', array $parame
$server['PATH_INFO'] = '';
$server['REQUEST_METHOD'] = strtoupper($method);

$components = parse_url($uri);
if (false === ($components = parse_url($uri)) && '/' === ($uri[0] ?? '')) {
$components = parse_url($uri.'#');
unset($components['fragment']);
}

if (isset($components['host'])) {
$server['SERVER_NAME'] = $components['host'];
$server['HTTP_HOST'] = $components['host'];
Expand Down
3 changes: 3 additions & 0 deletions Tests/RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ public function testCreate()
// Fragment should not be included in the URI
$request = Request::create('http://test.com/foo#bar');
$this->assertEquals('http://test.com/foo', $request->getUri());

$request = Request::create('/foo:123');
$this->assertEquals('http://localhost/foo:123', $request->getUri());
}

public function testCreateWithRequestUri()
Expand Down

0 comments on commit b61630e

Please sign in to comment.