diff --git a/src/Item.php b/src/Item.php index d638250cc..9e97e3bb0 100644 --- a/src/Item.php +++ b/src/Item.php @@ -359,7 +359,7 @@ public function get_thumbnail() { if (!isset($this->data['thumbnail'])) { if ($return = $this->get_item_tags(\SimplePie\SimplePie::NAMESPACE_MEDIARSS, 'thumbnail')) { - $thumbnail = $return[0]['attribs']['']; + $thumbnail = $return[0]['attribs'][''] ?? []; if (empty($thumbnail['url'])) { $this->data['thumbnail'] = null; } else { diff --git a/tests/Unit/ItemTest.php b/tests/Unit/ItemTest.php index b1ace1190..d36c9656e 100644 --- a/tests/Unit/ItemTest.php +++ b/tests/Unit/ItemTest.php @@ -5036,7 +5036,6 @@ public static function getThumbnailProvider(): iterable ]; } - /** * @dataProvider httpsDomainsProvider */ @@ -5115,4 +5114,33 @@ public static function httpsDomainsProvider(): iterable 'Hello', ]; } + + public function test_get_thumbnail_returns_null_when_attributes_are_missing(): void + { + $feed = new SimplePie(); + $feed->set_raw_data( + << + + Test thumbnail without attributes + Test thumbnail without attributes + http://example.org/tests/ + + Test thumbnail without attributes 1.1 + Test thumbnail without attributes 1.1 + http://example.net/tests/#1.1 + http://example.net/tests/#1.1 + + + + +XML + ); + $feed->enable_cache(false); + $feed->init(); + + $item = $feed->get_item(0); + self::assertInstanceOf(Item::class, $item); + self::assertNull($item->get_thumbnail()); + } }