From 8dc8e5b2f570fb71c208ccece00f5461216c015c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Wed, 25 Mar 2026 09:13:06 +0100 Subject: [PATCH] Item: Fix Undefined array key "" in get_thumbnail() (#970) Solve warning in the case of Downstream: fix https://github.com/FreshRSS/FreshRSS/issues/8614 --- src/Item.php | 2 +- tests/Unit/ItemTest.php | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/Item.php b/src/Item.php index 0a7cf151d..cf4a0a905 100644 --- a/src/Item.php +++ b/src/Item.php @@ -354,7 +354,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 a0fa8b5de..6d1676693 100644 --- a/tests/Unit/ItemTest.php +++ b/tests/Unit/ItemTest.php @@ -5035,4 +5035,33 @@ public static function getThumbnailProvider(): iterable 'http://example.net/link?a=%22b%22&c=%3Cd%3E', ]; } + + 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()); + } }