summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorgodbless <26397224+sak96@users.noreply.github.com>2021-08-17 23:07:58 +0530
committerGitHub <noreply@github.com>2021-08-17 19:37:58 +0200
commitcac665272a532879afc31a60321e91f2c9675e16 (patch)
treec9c14f51885551bfbbbc23ec04091c6db8d015cc /core
parent8b183915bee1419a0577196b19414529fca75432 (diff)
downloadAntennaPod-cac665272a532879afc31a60321e91f2c9675e16.zip
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".
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/syndication/namespace/atom/NSAtom.java4
-rw-r--r--core/src/test/java/de/danoeh/antennapod/core/syndication/handler/AtomParserTest.java29
-rw-r--r--core/src/test/resources/feed-atom-testEmptyRelLinks.xml14
3 files changed, 45 insertions, 2 deletions
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.
@@ -55,6 +56,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");
Feed feed = FeedParserTestHelper.runFeedParser(feedFile);
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 @@
+<?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>