kurtmckee/feedparser

Link w/o href considered alternate unconditionally

Rongronggg9 opened this issue · 0 comments

Consider an Atom entry like this (from https://www.dday.it/rss):

<entry>
    <id>https://www.dmove.it/news/monopattini-xiaomi</id>
    <published>2023-05-22T14:31:00+02:00</published>
    <updated>2023-05-22T14:41:04+02:00</updated>
    <link rel="alternate" type="text/html" href="https://www.dmove.it/news/monopattini-xiaomi"/>
    <link rel="enclosure" type="image/jpeg">https://dday.imgix.net/system/uploads/news/square_crop_img/45938/7b5b5a_Xiaomi_Quad.jpg?w=329&amp;h=256&amp;fit=crop&amp;auto=format%2Ccompress&amp;s=202aae143e9fc13b47e2c8511f2bc7db</link>
    <title>Xiaomi espande la gamma di monopattini: oltre al Pro, ora ci sono anche l’Electric Scooter 4 e il 4 Lite</title>
    <content type="html">&lt;img src='https://dday.imgix.net/system/uploads/news/square_crop_img/45938/7b5b5a_Xiaomi_Quad.jpg?w=329&amp;h=256&amp;fit=crop&amp;auto=format%2Ccompress&amp;s=202aae143e9fc13b47e2c8511f2bc7db'&gt;&lt;/br&gt;Xiaomi ha annunciato nuovi prodotto della gamma con due soluzioni più economiche. Electric Scooter 4 ed Electric Scooter 4 saranno disponibili dal 12 giugno.&lt;a href='https://www.dmove.it/news/monopattini-xiaomi'&gt;... Leggi tutto&lt;/a&gt;</content>
    <author>
      <name>dmove</name>
    </author>
</entry>
import feedparser
d = feedparser.parse(f'<feed>{entry}</feed>')
assert d.entries[0].link == 'https://dday.imgix.net/system/uploads/news/square_crop_img/45938/7b5b5a_Xiaomi_Quad.jpg?w=329&h=256&fit=crop&auto=format%2Ccompress&s=202aae143e9fc13b47e2c8511f2bc7db'

The element <link rel="enclosure" type="image/jpeg"> is misformatted, superseding <link rel="alternate" type="text/html" href="https://www.dmove.it/news/monopattini-xiaomi"/> to become entry.link. In theory, the rel="alternate" link should have the highest priority.