diff --git a/includes/Feed/AtomFeed.php b/includes/Feed/AtomFeed.php index 453943a39f7..5f9af7af398 100644 --- a/includes/Feed/AtomFeed.php +++ b/includes/Feed/AtomFeed.php @@ -100,7 +100,7 @@ class AtomFeed extends ChannelFeed { "url" => $this->xmlEncode( $this->urlUtils->expand( $item->getUrlUnescaped(), PROTO_CURRENT ) ?? '' ), - "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ), + "date" => $this->xmlEncodeNullable( $this->formatTime( $item->getDate() ) ), "description" => $item->getDescription(), "author" => $item->getAuthor() ]; diff --git a/includes/Feed/FeedItem.php b/includes/Feed/FeedItem.php index a67420afafc..93dd364fa15 100644 --- a/includes/Feed/FeedItem.php +++ b/includes/Feed/FeedItem.php @@ -100,6 +100,15 @@ class FeedItem { return htmlspecialchars( $string ); } + /** + * Encode $string so that it can be safely embedded in a XML document, + * returning `null` if $string was `null`. + * @since 1.44 + */ + public function xmlEncodeNullable( ?string $string ): ?string { + return $string !== null ? $this->xmlEncode( $string ) : null; + } + /** * Get the unique id of this item; already xml-encoded * diff --git a/includes/Feed/RSSFeed.php b/includes/Feed/RSSFeed.php index d19e54ca7e2..8ef86d6d580 100644 --- a/includes/Feed/RSSFeed.php +++ b/includes/Feed/RSSFeed.php @@ -78,7 +78,7 @@ class RSSFeed extends ChannelFeed { "permalink" => $item->rssIsPermalink, "uniqueID" => $item->getUniqueID(), "description" => $item->getDescription(), - "date" => $this->xmlEncode( $this->formatTime( $item->getDate() ) ), + "date" => $this->xmlEncodeNullable( $this->formatTime( $item->getDate() ) ), "author" => $item->getAuthor() ]; $comments = $item->getCommentsUnescaped();