Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Facades/Endpoint/URL.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ public function removeSiteUrl(?string $url): string
*/
public function makeRelative(?string $url): string
{
// Normalize duplicate leading slashes before parsing to avoid protocol-relative URL interpretation.
$url = preg_replace('#^/+#', '/', (string) $url);

$parsed = parse_url($url);

$url = $parsed['path'] ?? '/';
Expand Down
2 changes: 2 additions & 0 deletions tests/Facades/UrlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,8 @@ public static function relativeProvider()
'already relative nested route without trailing slash' => ['/foo/page', '/foo/page'],
'already relative nested route with trailing slash' => ['/foo/page/', '/foo/page'],
'already relative nested route without leading slash' => ['foo/page', '/foo/page'],
'duplicate leading slashes' => ['//page', '/page'],
'multiple duplicate leading slashes' => ['////page', '/page'],

'homepage without trailing slash and query param' => ['http://example.com?bar=baz', '/?bar=baz'],
'homepage with trailing slash and query param' => ['http://example.com/?bar=baz', '/?bar=baz'],
Expand Down
Loading