From deb781924ef364e48745757cf0ce57d77919d479 Mon Sep 17 00:00:00 2001 From: mishako Date: Sat, 27 Feb 2016 19:39:37 +0100 Subject: [PATCH] Use RSS v2 parser by default Changed RSS v2 parser to match any feed that has "rss" as root element. This makes Rome more lenient when handling feeds that don't adhere to the RSS spec, namely have the "version" attribute missing. --- .../main/java/com/rometools/rome/io/impl/RSS20Parser.java | 7 ++++++- .../java/com/rometools/rome/io/impl/RSS20ParserTest.java | 6 ++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/rome/src/main/java/com/rometools/rome/io/impl/RSS20Parser.java b/rome/src/main/java/com/rometools/rome/io/impl/RSS20Parser.java index b90c4e6..56bf541 100644 --- a/rome/src/main/java/com/rometools/rome/io/impl/RSS20Parser.java +++ b/rome/src/main/java/com/rometools/rome/io/impl/RSS20Parser.java @@ -51,7 +51,8 @@ public class RSS20Parser extends RSS094Parser { @Override public boolean isMyType(final Document document) { - return rootElementMatches(document) && versionMatches(document); + return rootElementMatches(document) + && (versionMatches(document) || versionAbsent(document)); } private boolean rootElementMatches(final Document document) { @@ -63,4 +64,8 @@ public class RSS20Parser extends RSS094Parser { return (version != null) && version.getValue().trim().startsWith(getRSSVersion()); } + + private boolean versionAbsent(final Document document) { + return document.getRootElement().getAttribute("version") == null; + } } diff --git a/rome/src/test/java/com/rometools/rome/io/impl/RSS20ParserTest.java b/rome/src/test/java/com/rometools/rome/io/impl/RSS20ParserTest.java index fff46c7..4493de2 100644 --- a/rome/src/test/java/com/rometools/rome/io/impl/RSS20ParserTest.java +++ b/rome/src/test/java/com/rometools/rome/io/impl/RSS20ParserTest.java @@ -44,4 +44,10 @@ public class RSS20ParserTest { document.setRootElement(new Element("rss").setAttribute("version", "2.0test")); assertTrue(parser.isMyType(document)); } + + @Test + public void testIsMyTypeVersionAbsent() { + document.setRootElement(new Element("rss")); + assertTrue(parser.isMyType(document)); + } }