Skip to content

Commit

Permalink
fixed special char encoding of feed item descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaishiyoku committed Jun 4, 2023
1 parent 5d7c6c8 commit 3b86427
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,4 +152,13 @@ public static function trimStringCollection(Collection $collection): Collection
/** @phpstan-ignore-next-line */
return $collection->map(fn($category) => Helper::trimOrDefaultNull($category))->filter();
}

public static function entityDecode(string $encoding, ?string $str): ?string
{
if (!$str) {
return $str;
}

return html_entity_decode($str, ENT_QUOTES | ENT_HTML5, $encoding);
}
}
5 changes: 3 additions & 2 deletions src/Models/Rss/FeedItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,8 @@ public static function fromZendFeedItem(EntryInterface $zendFeedItem, Client $ht

$feedItem = new self();

$content = html_entity_decode($zendFeedItem->getContent(), ENT_QUOTES | ENT_HTML5, $zendFeedItem->getEncoding());
$content = Helper::entityDecode($zendFeedItem->getEncoding(), $zendFeedItem->getContent());
$description = Helper::entityDecode($zendFeedItem->getEncoding(), $zendFeedItem->getDescription());
$imageUrls = $zendFeedItem->getPermalink() ? Helper::getImageUrlsForFeedItem($zendFeedItem->getPermalink(), $content, $httpClient) : new Collection();

$feedItem->setCategories(new Collection($zendFeedItem->getCategories()->getValues()));
Expand All @@ -340,7 +341,7 @@ public static function fromZendFeedItem(EntryInterface $zendFeedItem, Client $ht
$feedItem->setContent($content);
$feedItem->setCreatedAt($zendFeedItem->getDateCreated() == null ? null : Carbon::parse($zendFeedItem->getDateCreated()));
$feedItem->setUpdatedAt($zendFeedItem->getDateModified() == null ? null : Carbon::parse($zendFeedItem->getDateModified()));
$feedItem->setDescription($zendFeedItem->getDescription());
$feedItem->setDescription($description);
$feedItem->setEnclosureUrl(optional($zendFeedItem->getEnclosure(), fn($enclosure) => $enclosure->url));
$feedItem->setImageUrls($imageUrls);
$feedItem->setEncoding($zendFeedItem->getEncoding());
Expand Down

0 comments on commit 3b86427

Please sign in to comment.