From b61630eea65383a4d5cdfd0ca3b3e21defefcbd5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 10 Sep 2024 10:17:27 +0200 Subject: [PATCH] Work around parse_url() bug --- Request.php | 6 +++++- Tests/RequestTest.php | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Request.php b/Request.php index 75db0300b..561cb887f 100644 --- a/Request.php +++ b/Request.php @@ -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']; diff --git a/Tests/RequestTest.php b/Tests/RequestTest.php index 395df09c5..082e8695c 100644 --- a/Tests/RequestTest.php +++ b/Tests/RequestTest.php @@ -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()