Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't overwrite image title and links when "itunes:image" is present #315

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ bug report!
* `Aaron Swartz <http://www.aaronsw.com/>`_
* `Jakub Wilk <http://jwilk.net/>`_
* `Nestor Rodriguez <https://github.com/n3s7or>`_
* `Niko Abeler <https://github.com/h4kor>`_
10 changes: 6 additions & 4 deletions feedparser/namespaces/itunes.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,12 @@ def _start_itunes_category(self, attrs_d):

def _start_itunes_image(self, attrs_d):
self.push('itunes_image', 0)
if attrs_d.get('href'):
self._get_context()['image'] = FeedParserDict({'href': attrs_d.get('href')})
elif attrs_d.get('url'):
self._get_context()['image'] = FeedParserDict({'href': attrs_d.get('url')})
href = attrs_d.get('href', attrs_d.get('url', None))
if href:
if "image" not in self._get_context():
self._get_context()['image'] = FeedParserDict({'href': href})
else:
self._get_context()['image']['href'] = href
_start_itunes_link = _start_itunes_image

def _end_itunes_block(self):
Expand Down
14 changes: 14 additions & 0 deletions tests/entities/image_and_itunes_image.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!--
Description: itunes:image does not overwrite existing image title and link
Expect: feed['image']["title"] == 'Image Test' and feed['image']["links"][0]["href"] == 'https://example.com'
-->
<rss>
<channel>
<image>
<url>https://example.com/image.png</url>
<title>Image Test</title>
<link>https://example.com</link>
</image>
<itunes:image href="https://example.com/image.png"/>
</channel>
</rss>