summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorAccalia Elementia <accalia@elementia.me>2022-05-24 11:07:50 -0400
committerGitHub <noreply@github.com>2022-05-24 17:07:50 +0200
commitfdf037e7287616b5211f8f8f7c8ce85b260d781e (patch)
tree6371e0fce359c48f40450929bd0dade97cc7aa1e /lib
parent684af84ea957ff160d49d44826525d1684b6f975 (diff)
Use Feed Link as GUID when Feed omits Guid. (#1785)
* Use Feed Link as GUID when Feed omits Guid. As noted in nextcloud/news#1702 some feeds omit the GUID and are therefore not a valid RSS feed. nextcloud/news#1738 resolved the issue to allow valid feeds to update correctly when an invalid feed is present. This commit allows parsing of the invalid feed as well by assuming that the item link of the feed is unique to the feed and using it in place of the GUID when the feed omits the GUID. This will allow NextCloud News to accept and behave like many other popular feed aggregators when presented with such an invalid feed. Signed-off-by: Accalia <Accalia@Elementia.me> * Add basic Logging when using fallback guid Signed-off-by: Accalia <Accalia@Elementia.me> * Add basic Logging when using fallback guid - Fix Fatfinger Typo Signed-off-by: Accalia <Accalia@Elementia.me> * Add basic Logging when using fallback guid - Update tests to account for additional logging Signed-off-by: Accalia <Accalia@Elementia.me>
Diffstat (limited to 'lib')
-rwxr-xr-xlib/Fetcher/FeedFetcher.php24
1 files changed, 19 insertions, 5 deletions
diff --git a/lib/Fetcher/FeedFetcher.php b/lib/Fetcher/FeedFetcher.php
index a6ddbacb5..27421f525 100755
--- a/lib/Fetcher/FeedFetcher.php
+++ b/lib/Fetcher/FeedFetcher.php
@@ -233,11 +233,25 @@ class FeedFetcher implements IFeedFetcher
{
$item = new Item();
$item->setUnread(true);
- $item->setUrl($parsedItem->getLink());
- if ($parsedItem->getPublicId() == null) {
+ $itemLink = $parsedItem->getLink();
+ $itemTitle = $parsedItem->getTitle();
+ $item->setUrl($itemLink);
+ $publicId = $parsedItem->getPublicId();
+ if ($publicId == null) {
+ // Fallback on using the URL as the guid for the feed item if no guid provided by feed
+ $this->logger->debug(
+ "Feed item {title} with link {link} did not expose a guid, falling back to using link as guid",
+ [
+ 'title' => $itemTitle,
+ 'link' => $itemLink
+ ]
+ );
+ $publicId = $itemLink;
+ }
+ if ($publicId == null) {
throw new ReadErrorException("Malformed feed: item has no GUID");
}
- $item->setGuid($parsedItem->getPublicId());
+ $item->setGuid($publicId);
$item->setGuidHash(md5($item->getGuid()));
$lastModified = $parsedItem->getLastModified() ?? new DateTime();
@@ -255,8 +269,8 @@ class FeedFetcher implements IFeedFetcher
$item->setRtl($RTL);
// unescape content because angularjs helps against XSS
- if ($parsedItem->getTitle() !== null) {
- $item->setTitle($this->decodeTwice($parsedItem->getTitle()));
+ if ($itemTitle !== null) {
+ $item->setTitle($this->decodeTwice($itemTitle));
}
$author = $parsedItem->getAuthor();
if ($author !== null && $author->getName() !== null) {