Skip to content

Commit 3781c8e

Browse files
committed
respect URL scheme in pathJoin
1 parent 8545265 commit 3781c8e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

resources/lib/utils.php

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -72,15 +72,22 @@ function mbDetectEncoding(string $string, ?array $encodings = null, mixed $_ = n
7272
}
7373

7474
/* https://stackoverflow.com/a/15575293/18696276 */
75-
function pathJoin()
75+
function pathNormalize(string $path)
7676
{
77-
$paths = [];
78-
foreach (func_get_args() as $arg) {
79-
if ($arg !== "") {
80-
$paths[] = $arg;
81-
}
77+
return preg_replace("#/+#", "/", $path);
78+
}
79+
80+
function pathJoin(...$path_components)
81+
{
82+
$path = join("/", $path_components);
83+
// if URL starts with a "scheme" like "https://", do not try to alter the slashes in the scheme
84+
if (preg_match("#^\w+://#", $path)) {
85+
$matches = [];
86+
preg_match("#(^\w+://)(.*)#", $path, $matches);
87+
return $matches[1] . pathNormalize($matches[2]);
88+
} else {
89+
return pathNormalize($path);
8290
}
83-
return preg_replace("#/+#", "/", join("/", $paths));
8491
}
8592

8693
function getURL(...$path_components)

0 commit comments

Comments
 (0)