Skip to content

Commit

Permalink
fix: do not fail on invalid time strings
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz authored and Grotax committed Jan 9, 2025
1 parent 6dbfa9a commit 3361c60
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ You can also check [on GitHub](https://github.com/nextcloud/news/releases), the

### Fixed
- fix proxy port removed if standard port for the protocol (#3027)

- background updater may stumble over invalid datetime strings from feeds (#3028)

# Releases
## [25.2.0-beta.3] - 2025-01-04
Expand Down
20 changes: 14 additions & 6 deletions lib/Fetcher/FeedFetcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ public function fetch(
$url2->setUserinfo(rawurlencode($user), rawurlencode($password));
}
if (!is_null($httpLastModified) && trim($httpLastModified) !== '') {
$lastModified = new DateTime($httpLastModified);
try {
$lastModified = new DateTime($httpLastModified);
} catch (\Exception) {
$lastModified = null;
}
} else {
$lastModified = null;
}
Expand Down Expand Up @@ -294,11 +298,15 @@ protected function buildItem(
$item->setGuidHash(md5($item->getGuid()));

$lastModified = $parsedItem->getLastModified() ?? new DateTime();
if ($parsedItem->getValue('pubDate') !== null) {
$pubDT = new DateTime($parsedItem->getValue('pubDate'));
} elseif ($parsedItem->getValue('published') !== null) {
$pubDT = new DateTime($parsedItem->getValue('published'));
} else {
try {
if ($parsedItem->getValue('pubDate') !== null) {
$pubDT = new DateTime($parsedItem->getValue('pubDate'));
} elseif ($parsedItem->getValue('published') !== null) {
$pubDT = new DateTime($parsedItem->getValue('published'));
} else {
$pubDT = $lastModified;
}
} catch (\Exception) {
$pubDT = $lastModified;
}

Expand Down

0 comments on commit 3361c60

Please sign in to comment.