Skip to content

Commit b19cf8b

Browse files
committed
Fix Undefined array key "" in get_thumbnail()
Downstream: fix FreshRSS/FreshRSS#8614
1 parent 4f59520 commit b19cf8b

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/Item.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ public function get_thumbnail()
354354
{
355355
if (!isset($this->data['thumbnail'])) {
356356
if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'thumbnail')) {
357-
$thumbnail = $return[0]['attribs'][''];
357+
$thumbnail = $return[0]['attribs'][''] ?? [];
358358
if (empty($thumbnail['url'])) {
359359
$this->data['thumbnail'] = null;
360360
} else {

tests/Unit/ItemTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5035,4 +5035,33 @@ public static function getThumbnailProvider(): iterable
50355035
'http://example.net/link?a=%22b%22&c=%3Cd%3E',
50365036
];
50375037
}
5038+
5039+
public function test_get_thumbnail_returns_null_when_attributes_are_missing(): void
5040+
{
5041+
$feed = new SimplePie();
5042+
$feed->set_raw_data(
5043+
<<<XML
5044+
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
5045+
<channel>
5046+
<title>Test thumbnail without attributes</title>
5047+
<description>Test thumbnail without attributes</description>
5048+
<link>http://example.org/tests/</link>
5049+
<item>
5050+
<title>Test thumbnail without attributes 1.1</title>
5051+
<description>Test thumbnail without attributes 1.1</description>
5052+
<guid>http://example.net/tests/#1.1</guid>
5053+
<link>http://example.net/tests/#1.1</link>
5054+
<media:thumbnail />
5055+
</item>
5056+
</channel>
5057+
</rss>
5058+
XML
5059+
);
5060+
$feed->enable_cache(false);
5061+
$feed->init();
5062+
5063+
$item = $feed->get_item(0);
5064+
self::assertInstanceOf(Item::class, $item);
5065+
self::assertNull($item->get_thumbnail());
5066+
}
50385067
}

0 commit comments

Comments
 (0)