Ignore item tags that are not inside a channel
This commit is contained in:
parent
345aad4148
commit
bb9936f696
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>
|
Loading…
Reference in New Issue