Merge pull request #8867 from annando/issue-8866

Issue 8866: Fix fetching feed links with missing base
This commit is contained in:
Hypolite Petovan 2020-07-12 09:25:15 -04:00 committed by GitHub
commit 5fefe7e96f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 0 deletions

View file

@ -337,6 +337,10 @@ class Feed
$item["uri"] = $item["plink"]; $item["uri"] = $item["plink"];
} }
// Add the base path if missing
$item["uri"] = Network::addBasePath($item["uri"], $basepath);
$item["plink"] = Network::addBasePath($item["plink"], $basepath);
$orig_plink = $item["plink"]; $orig_plink = $item["plink"];
$item["plink"] = Network::finalUrl($item["plink"]); $item["plink"] = Network::finalUrl($item["plink"]);

View file

@ -625,6 +625,26 @@ class Network
return $url; return $url;
} }
/**
* Add a missing base path (scheme and host) to a given url
*
* @param string $url
* @param string $basepath
* @return string url
*/
public static function addBasePath(string $url, string $basepath)
{
if (!empty(parse_url($url, PHP_URL_SCHEME)) || empty(parse_url($basepath, PHP_URL_SCHEME)) || empty($url) || empty(parse_url($url))) {
return $url;
}
$base = ['scheme' => parse_url($basepath, PHP_URL_SCHEME),
'host' => parse_url($basepath, PHP_URL_HOST)];
$parts = array_merge($base, parse_url('/' . ltrim($url, '/')));
return self::unparseURL($parts);
}
/** /**
* Returns the original URL of the provided URL * Returns the original URL of the provided URL
* *