From cac665272a532879afc31a60321e91f2c9675e16 Mon Sep 17 00:00:00 2001 From: godbless <26397224+sak96@users.noreply.github.com> Date: Tue, 17 Aug 2021 23:07:58 +0530 Subject: [PATCH] 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". --- .../syndication/namespace/atom/NSAtom.java | 4 +-- .../syndication/handler/AtomParserTest.java | 29 +++++++++++++++++++ .../resources/feed-atom-testEmptyRelLinks.xml | 14 +++++++++ 3 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 core/src/test/resources/feed-atom-testEmptyRelLinks.xml diff --git a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java index 6d459075a..b93f41771 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java +++ b/core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java @@ -81,7 +81,7 @@ public class NSAtom extends Namespace { String rel = attributes.getValue(LINK_REL); SyndElement parent = state.getTagstack().peek(); if (parent.getName().matches(isFeedItem)) { - if (LINK_REL_ALTERNATE.equals(rel)) { + if (rel == null || LINK_REL_ALTERNATE.equals(rel)) { state.getCurrentItem().setLink(href); } else if (LINK_REL_ENCLOSURE.equals(rel)) { String strSize = attributes.getValue(LINK_LENGTH); @@ -107,7 +107,7 @@ public class NSAtom extends Namespace { state.getCurrentItem().setPaymentLink(href); } } 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); /* * Use as link if a) no type-attribute is given and diff --git a/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java b/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java index 2acc73204..36ca7f0d8 100644 --- a/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java +++ b/core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java @@ -14,6 +14,7 @@ import de.danoeh.antennapod.model.feed.FeedMedia; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; /** * 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 public void testLogoWithWhitespace() throws Exception { File feedFile = FeedParserTestHelper.getFeedFile("feed-atom-testLogoWithWhitespace.xml"); diff --git a/core/src/test/resources/feed-atom-testEmptyRelLinks.xml b/core/src/test/resources/feed-atom-testEmptyRelLinks.xml new file mode 100644 index 000000000..04c28ef67 --- /dev/null +++ b/core/src/test/resources/feed-atom-testEmptyRelLinks.xml @@ -0,0 +1,14 @@ + + + http://example.com/feed + title + + This is the description + http://example.com/picture + + http://example.com/item-0 + item-0 + + 1970-01-01T00:00:00Z + +