From 4c76e4176a5472c5afe504194d7bbef5cfdd1703 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 --- Tests/UriResolverTest.php | 1 + UriResolver.php | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Tests/UriResolverTest.php b/Tests/UriResolverTest.php index ab98cb5..e0a2a99 100644 --- a/Tests/UriResolverTest.php +++ b/Tests/UriResolverTest.php @@ -86,6 +86,7 @@ public static function provideResolverTests() ['foo', 'http://localhost#bar', 'http://localhost/foo'], ['http://', 'http://localhost', 'http://'], + ['/foo:123', 'http://localhost', 'http://localhost/foo:123'], ]; } } diff --git a/UriResolver.php b/UriResolver.php index 5ff2245..4140dc0 100644 --- a/UriResolver.php +++ b/UriResolver.php @@ -32,8 +32,12 @@ public static function resolve(string $uri, ?string $baseUri): string { $uri = trim($uri); + if (false === ($scheme = parse_url($uri, \PHP_URL_SCHEME)) && '/' === ($uri[0] ?? '')) { + $scheme = parse_url($uri.'#', \PHP_URL_SCHEME); + } + // absolute URL? - if (null !== parse_url($uri, \PHP_URL_SCHEME)) { + if (null !== $scheme) { return $uri; }