diff --git a/deluge/ui/tracker_icons.py b/deluge/ui/tracker_icons.py index 5a6aa3b68..b079738f3 100644 --- a/deluge/ui/tracker_icons.py +++ b/deluge/ui/tracker_icons.py @@ -424,8 +424,15 @@ class FaviconParser(HTMLParser): href = value elif attr == "type": type = value - if href and type: - self.icons.append((href, type)) + if href: + try: + mimetype = extension_to_mimetype(href.rpartition('.')[2]) + except KeyError: + pass + else: + type = mimetype + if type: + self.icons.append((href, type)) def handle_endtag(self, tag): if tag == "head": diff --git a/tests/openbt.png b/tests/openbt.png new file mode 100644 index 000000000..270d617ae Binary files /dev/null and b/tests/openbt.png differ diff --git a/tests/test_tracker_icons.py b/tests/test_tracker_icons.py index 702e648fe..5ff7241e6 100644 --- a/tests/test_tracker_icons.py +++ b/tests/test_tracker_icons.py @@ -12,7 +12,7 @@ common.set_tmp_config_dir() icons = TrackerIcons() class TrackerIconsTestCase(unittest.TestCase): - def test_get_png(self): + def test_get_deluge_png(self): # Deluge has a png favicon link icon = TrackerIcon("../deluge.png") d = icons.get("deluge-torrent.org") @@ -20,7 +20,7 @@ class TrackerIconsTestCase(unittest.TestCase): d.addCallback(self.assertEquals, icon) return d - def test_get_ico(self): + def test_get_google_ico(self): # Google doesn't have any icon links # So instead we'll grab its favicon.ico icon = TrackerIcon("../google.ico") @@ -29,7 +29,7 @@ class TrackerIconsTestCase(unittest.TestCase): d.addCallback(self.assertEquals, icon) return d - def test_get_ico_with_redirect(self): + def test_get_google_ico_with_redirect(self): # google.com redirects to www.google.com icon = TrackerIcon("../google.ico") d = icons.get("google.com") @@ -44,3 +44,11 @@ class TrackerIconsTestCase(unittest.TestCase): d.addCallback(self.assertNotIdentical, None) d.addCallback(self.assertEquals, icon) return d + + def test_get_openbt_png(self): + # openbittorrent.com has an incorrect type (image/gif) + icon = TrackerIcon("../openbt.png") + d = icons.get("openbittorrent.com") + d.addCallback(self.assertNotIdentical, None) + d.addCallback(self.assertEquals, icon) + return d