Merge pull request #9727 from annando/notice

Fix a notice when the path is empty
This commit is contained in:
Hypolite Petovan 2020-12-31 07:15:12 -05:00 committed by GitHub
commit 422de110e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1801,26 +1801,28 @@ class Probe
$hrefParts = parse_url($href); $hrefParts = parse_url($href);
// Root path case (/path) including relative scheme case (//host/path) if (!empty($hrefParts['path'])) {
if ($hrefParts['path'] && $hrefParts['path'][0] == '/') { // Root path case (/path) including relative scheme case (//host/path)
$path = $hrefParts['path']; if ($hrefParts['path'] && $hrefParts['path'][0] == '/') {
} else { $path = $hrefParts['path'];
$path = $path . '/' . $hrefParts['path']; } else {
$path = $path . '/' . $hrefParts['path'];
// Resolve arbitrary relative path // Resolve arbitrary relative path
// Lifted from https://www.php.net/manual/en/function.realpath.php#84012 // Lifted from https://www.php.net/manual/en/function.realpath.php#84012
$parts = array_filter(explode('/', $path), 'strlen'); $parts = array_filter(explode('/', $path), 'strlen');
$absolutes = array(); $absolutes = array();
foreach ($parts as $part) { foreach ($parts as $part) {
if ('.' == $part) continue; if ('.' == $part) continue;
if ('..' == $part) { if ('..' == $part) {
array_pop($absolutes); array_pop($absolutes);
} else { } else {
$absolutes[] = $part; $absolutes[] = $part;
}
} }
}
$path = '/' . implode('/', $absolutes); $path = '/' . implode('/', $absolutes);
}
} }
// Relative scheme case (//host/path) // Relative scheme case (//host/path)