Skip to content

Commit 0a86bab

Browse files
committed
don't overwrite image title and link when itunes:image is present
1 parent 5fcb3ae commit 0a86bab

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

CONTRIBUTORS.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,4 @@ bug report!
2828
* `Aaron Swartz <http://www.aaronsw.com/>`_
2929
* `Jakub Wilk <http://jwilk.net/>`_
3030
* `Nestor Rodriguez <https://github.com/n3s7or>`_
31+
* `Niko Abeler <https://github.com/h4kor>`_

feedparser/namespaces/itunes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,12 @@ def _start_itunes_category(self, attrs_d):
9191

9292
def _start_itunes_image(self, attrs_d):
9393
self.push('itunes_image', 0)
94-
if attrs_d.get('href'):
95-
self._get_context()['image'] = FeedParserDict({'href': attrs_d.get('href')})
96-
elif attrs_d.get('url'):
97-
self._get_context()['image'] = FeedParserDict({'href': attrs_d.get('url')})
94+
href = attrs_d.get('href', attrs_d.get('url', None))
95+
if href:
96+
if "image" not in self._get_context():
97+
self._get_context()['image'] = FeedParserDict({'href': href})
98+
else:
99+
self._get_context()['image']['href'] = href
98100
_start_itunes_link = _start_itunes_image
99101

100102
def _end_itunes_block(self):
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--
2+
Description: itunes:image does not overwrite existing image title and link
3+
Expect: feed['image']["title"] == 'Image Test' and feed['image']["links"][0]["href"] == 'https://example.com'
4+
-->
5+
<rss>
6+
<channel>
7+
<image>
8+
<url>https://example.com/image.png</url>
9+
<title>Image Test</title>
10+
<link>https://example.com</link>
11+
</image>
12+
<itunes:image href="https://example.com/image.png"/>
13+
</channel>
14+
</rss>

0 commit comments

Comments
 (0)