diff options
author | ByteHamster <info@bytehamster.com> | 2021-10-30 21:58:17 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2021-10-30 21:58:17 +0200 |
commit | bb9936f696d5a658b0a8007a80e76fc511515115 (patch) | |
tree | f9d1cc0e3165b10a197a0cecb7ea983480c4fcb8 | |
parent | 345aad4148f133477e40c232a8e855dfd28e0654 (diff) | |
download | AntennaPod-bb9936f696d5a658b0a8007a80e76fc511515115.zip |
Ignore item tags that are not inside a channel
3 files changed, 25 insertions, 6 deletions
diff --git a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/namespace/Rss20.java b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/namespace/Rss20.java index a49cd16dd..9ac77a5e6 100644 --- a/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/namespace/Rss20.java +++ b/parser/feed/src/main/java/de/danoeh/antennapod/parser/feed/namespace/Rss20.java @@ -39,14 +39,12 @@ public class Rss20 extends Namespace { private static final String ENC_TYPE = "type"; @Override - public SyndElement handleElementStart(String localName, HandlerState state, - Attributes attributes) { - if (ITEM.equals(localName)) { + public SyndElement handleElementStart(String localName, HandlerState state, Attributes attributes) { + if (ITEM.equals(localName) && CHANNEL.equals(state.getTagstack().lastElement().getName())) { state.setCurrentItem(new FeedItem()); state.getItems().add(state.getCurrentItem()); state.getCurrentItem().setFeed(state.getFeed()); - - } else if (ENCLOSURE.equals(localName)) { + } else if (ENCLOSURE.equals(localName) && ITEM.equals(state.getTagstack().peek().getName())) { String type = attributes.getValue(ENC_TYPE); String url = attributes.getValue(ENC_URL); @@ -72,7 +70,6 @@ public class Rss20 extends Namespace { FeedMedia media = new FeedMedia(state.getCurrentItem(), url, size, type); state.getCurrentItem().setMedia(media); } - } return new SyndElement(localName, this); } diff --git a/parser/feed/src/test/java/de/danoeh/antennapod/parser/feed/element/namespace/RssParserTest.java b/parser/feed/src/test/java/de/danoeh/antennapod/parser/feed/element/namespace/RssParserTest.java index 8f8942d7b..88ac5c731 100644 --- a/parser/feed/src/test/java/de/danoeh/antennapod/parser/feed/element/namespace/RssParserTest.java +++ b/parser/feed/src/test/java/de/danoeh/antennapod/parser/feed/element/namespace/RssParserTest.java @@ -96,4 +96,12 @@ public class RssParserTest { assertTrue(TextUtils.isEmpty(feed.getPaymentLinks().get(2).content)); assertEquals("https://example.com/funding3", feed.getPaymentLinks().get(2).url); } + + @Test + public void testUnsupportedElements() throws Exception { + File feedFile = FeedParserTestHelper.getFeedFile("feed-rss-testUnsupportedElements.xml"); + Feed feed = FeedParserTestHelper.runFeedParser(feedFile); + assertEquals(1, feed.getItems().size()); + assertEquals("item-0", feed.getItems().get(0).getTitle()); + } } diff --git a/parser/feed/src/test/resources/feed-rss-testUnsupportedElements.xml b/parser/feed/src/test/resources/feed-rss-testUnsupportedElements.xml new file mode 100644 index 000000000..f21ca7ebd --- /dev/null +++ b/parser/feed/src/test/resources/feed-rss-testUnsupportedElements.xml @@ -0,0 +1,14 @@ +<?xml version='1.0' encoding='UTF-8' ?> +<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"> + <channel> + <title>title</title> + <item> + <title>item-0</title> + </item> + <unsupported-element> + <item> + <title>item-1</title> + </item> + </unsupported-element> + </channel> +</rss> |