Skip to content

Commit 8b73e30

Browse files
committed
Improved getSubPath
1 parent 17d75e3 commit 8b73e30

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

app/Utils/UrlUtils.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,15 @@ static function getSubPath(string $url) : string {
2323
if(!$doesMatch || !isset($matches[1])) {
2424
return '/';
2525
}
26-
27-
$subpathUrl = trim($matches[1]);
28-
return Str::start(trim($subpathUrl, '/'), '/');
26+
$trimDefaultCharacters = " \n\r\t\v\0";
27+
// Remove all irrelevant characters from the subpath
28+
// including all leading and trailing slashes.
29+
$subPathUrl = trim($matches[1], $trimDefaultCharacters . '/');
30+
if(empty($subPathUrl)) {
31+
return '/';
32+
}
33+
34+
// Add leading slash to the subpath.
35+
return '/' . $subPathUrl;
2936
}
3037
}

0 commit comments

Comments
 (0)