Treat link without rel as rel=alternate (#5347)

src: https://datatracker.ietf.org/doc/html/rfc4287#section-4.2.7.2

If the "rel" attribute is not present, the link element MUST
be interpreted as if the link relation type is
"alternate".
This commit is contained in:
godbless 2021-08-17 23:07:58 +05:30 committed by GitHub
parent 8b183915be
commit cac665272a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 2 deletions

View File

@ -81,7 +81,7 @@ public class NSAtom extends Namespace {
String rel = attributes.getValue(LINK_REL); String rel = attributes.getValue(LINK_REL);
SyndElement parent = state.getTagstack().peek(); SyndElement parent = state.getTagstack().peek();
if (parent.getName().matches(isFeedItem)) { if (parent.getName().matches(isFeedItem)) {
if (LINK_REL_ALTERNATE.equals(rel)) { if (rel == null || LINK_REL_ALTERNATE.equals(rel)) {
state.getCurrentItem().setLink(href); state.getCurrentItem().setLink(href);
} else if (LINK_REL_ENCLOSURE.equals(rel)) { } else if (LINK_REL_ENCLOSURE.equals(rel)) {
String strSize = attributes.getValue(LINK_LENGTH); String strSize = attributes.getValue(LINK_LENGTH);
@ -107,7 +107,7 @@ public class NSAtom extends Namespace {
state.getCurrentItem().setPaymentLink(href); state.getCurrentItem().setPaymentLink(href);
} }
} else if (parent.getName().matches(isFeed)) { } else if (parent.getName().matches(isFeed)) {
if (LINK_REL_ALTERNATE.equals(rel)) { if (rel == null || LINK_REL_ALTERNATE.equals(rel)) {
String type = attributes.getValue(LINK_TYPE); String type = attributes.getValue(LINK_TYPE);
/* /*
* Use as link if a) no type-attribute is given and * Use as link if a) no type-attribute is given and

View File

@ -14,6 +14,7 @@ import de.danoeh.antennapod.model.feed.FeedMedia;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull; import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertFalse;
/** /**
* Tests for Atom feeds in FeedHandler. * Tests for Atom feeds in FeedHandler.
@ -54,6 +55,34 @@ public class AtomParserTest {
} }
} }
@Test
public void testEmptyRelLinks() throws Exception {
File feedFile = FeedParserTestHelper.getFeedFile("feed-atom-testEmptyRelLinks.xml");
Feed feed = FeedParserTestHelper.runFeedParser(feedFile);
assertEquals(Feed.TYPE_ATOM1, feed.getType());
assertEquals("title", feed.getTitle());
assertEquals("http://example.com/feed", feed.getFeedIdentifier());
assertEquals("http://example.com", feed.getLink());
assertEquals("This is the description", feed.getDescription());
assertNull(feed.getPaymentLinks());
assertEquals("http://example.com/picture", feed.getImageUrl());
assertEquals(1, feed.getItems().size());
// feed entry
FeedItem item = feed.getItems().get(0);
assertEquals("http://example.com/item-0", item.getItemIdentifier());
assertEquals("item-0", item.getTitle());
assertNull(item.getDescription());
assertEquals("http://example.com/items/0", item.getLink());
assertEquals(new Date(0), item.getPubDate());
assertNull(item.getPaymentLink());
assertEquals("http://example.com/picture", item.getImageLocation());
// media
assertFalse(item.hasMedia());
// chapters
assertNull(item.getChapters());
}
@Test @Test
public void testLogoWithWhitespace() throws Exception { public void testLogoWithWhitespace() throws Exception {
File feedFile = FeedParserTestHelper.getFeedFile("feed-atom-testLogoWithWhitespace.xml"); File feedFile = FeedParserTestHelper.getFeedFile("feed-atom-testLogoWithWhitespace.xml");

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<id>http://example.com/feed</id>
<title>title</title>
<link href="http://example.com" />
<subtitle>This is the description</subtitle>
<logo>http://example.com/picture</logo>
<entry>
<id>http://example.com/item-0</id>
<title>item-0</title>
<link href="http://example.com/items/0" />
<published>1970-01-01T00:00:00Z</published>
</entry>
</feed>