Skip to content

Commit 451a9b3

Browse files
committed
Merge branch 'master' into merge-fix-get-thumbnail
2 parents 144f082 + 8dc8e5b commit 451a9b3

2 files changed

Lines changed: 30 additions & 2 deletions

File tree

src/Item.php

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

tests/Unit/ItemTest.php

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5036,7 +5036,6 @@ public static function getThumbnailProvider(): iterable
50365036
];
50375037
}
50385038

5039-
50405039
/**
50415040
* @dataProvider httpsDomainsProvider
50425041
*/
@@ -5115,4 +5114,33 @@ public static function httpsDomainsProvider(): iterable
51155114
'<a href="http://example.com/tests/test1">Hello</a>',
51165115
];
51175116
}
5117+
5118+
public function test_get_thumbnail_returns_null_when_attributes_are_missing(): void
5119+
{
5120+
$feed = new SimplePie();
5121+
$feed->set_raw_data(
5122+
<<<XML
5123+
<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/">
5124+
<channel>
5125+
<title>Test thumbnail without attributes</title>
5126+
<description>Test thumbnail without attributes</description>
5127+
<link>http://example.org/tests/</link>
5128+
<item>
5129+
<title>Test thumbnail without attributes 1.1</title>
5130+
<description>Test thumbnail without attributes 1.1</description>
5131+
<guid>http://example.net/tests/#1.1</guid>
5132+
<link>http://example.net/tests/#1.1</link>
5133+
<media:thumbnail />
5134+
</item>
5135+
</channel>
5136+
</rss>
5137+
XML
5138+
);
5139+
$feed->enable_cache(false);
5140+
$feed->init();
5141+
5142+
$item = $feed->get_item(0);
5143+
self::assertInstanceOf(Item::class, $item);
5144+
self::assertNull($item->get_thumbnail());
5145+
}
51185146
}

0 commit comments

Comments
 (0)