From 81928727f2646fdbdb7d583103e57e2b457b6769 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 12 Jul 2020 12:45:34 +0000 Subject: [PATCH] Issue 8866: Fix fetching feed links with missing base --- src/Protocol/Feed.php | 4 ++++ src/Util/Network.php | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Protocol/Feed.php b/src/Protocol/Feed.php index 3518298321..c3f6a4e0b7 100644 --- a/src/Protocol/Feed.php +++ b/src/Protocol/Feed.php @@ -337,6 +337,10 @@ class Feed $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"]; $item["plink"] = Network::finalUrl($item["plink"]); diff --git a/src/Util/Network.php b/src/Util/Network.php index 6b73369d32..ddec359907 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -625,6 +625,26 @@ class Network 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 *