Modern Apps git

← Modern-Apps.git

news: the fallback crawl no longer drops every RDF/RSS 1.0 article

Commit
ee4300e3fe602869c6b989de33e15fb3db0b5817
Author
Vayun Mathur <[email protected]>
When
2026-12-01 04:13 UTC (5 days ago)
Parents
25abc51
SitemapParser routed RDF documents to extractRss but its
block scanner searched for the literal string "<item>" —
and RSS 1.0 items are always <item rdf:about=...>, so the
scanner never matched and the parse silently returned zero
articles. Catalog sources shaped this way (tagesschau's
newsticker.rdf, the generated hna/merkur/tz .rdf feeds) lost
their entire article set whenever the fallback crawl ran,
rather than the origin feed. The same literal-match flaw
dropped Atom <entry> tags carrying attributes.

forEachBlock now matches the tag-name prefix, requires the
next character to be > or whitespace (so <urlset> never
matches <url> and a channel's <items> table of contents is
not an item), and skips to the opening tag's >. Two
regression tests encode the RDF and attributed-Atom inputs
(empty pre-fix). No repository/ViewModel change, and story
grouping still uses only the server's exact storyId — the
app still never clusters locally. Verified:
:news:testDevUnitTest and lint BUILD SUCCESSFUL.

Diff

news/src/main/java/com/vayunmathur/news/domain/SitemapParser.kt
diff --git a/news/src/main/java/com/vayunmathur/news/domain/SitemapParser.kt b/news/src/main/java/com/vayunmathur/news/domain/SitemapParser.ktindex 2344ee5804..b7a653ef2f 100644--- a/news/src/main/java/com/vayunmathur/news/domain/SitemapParser.kt+++ b/news/src/main/java/com/vayunmathur/news/domain/SitemapParser.kt@@ -8,7 +8,7 @@ data class ParsedFeed(  /**  * Pure parser for Google News sitemaps (urlset + news extension), plain- * urlsets, sitemap indexes, RSS 2.0 and Atom.+ * urlsets, sitemap indexes, RSS (2.0 and RDF/RSS 1.0) and Atom.  *  * Linear scan only: entries are located with [String.indexOf] and each  * entry block is scanned in isolation. There is deliberately no@@ -104,14 +104,32 @@ object SitemapParser {      /**      * Visits each `<open>…</close>` block in order, in one forward pass.-     * Unterminated trailing blocks are ignored.+     * The opening tag may carry attributes (`<item rdf:about="…">` in+     * RDF/RSS 1.0 feeds, `<entry xml:lang="…">` in Atom): only the tag+     * name must match, and a longer tag name with the same prefix+     * (`<urlset>` for `<url>`) is not a match. Self-closing and+     * unterminated trailing blocks are ignored.      */     private inline fun forEachBlock(doc: String, open: String, close: String, visit: (String) -> Unit) {+        val prefix = open.removeSuffix(">")         var from = 0         while (true) {-            val start = doc.indexOf(open, from)+            val start = doc.indexOf(prefix, from)             if (start < 0) return-            val contentStart = start + open.length+            val afterName = start + prefix.length+            if (afterName >= doc.length) return+            val boundary = doc[afterName]+            if (boundary != '>' && !boundary.isWhitespace()) {+                from = afterName+                continue+            }+            val tagEnd = doc.indexOf('>', afterName)+            if (tagEnd < 0) return+            if (doc[tagEnd - 1] == '/') {+                from = tagEnd + 1+                continue+            }+            val contentStart = tagEnd + 1             val end = doc.indexOf(close, contentStart)             if (end < 0) return             visit(doc.substring(contentStart, end))
news/src/test/java/com/vayunmathur/news/domain/SitemapParserTest.kt
diff --git a/news/src/test/java/com/vayunmathur/news/domain/SitemapParserTest.kt b/news/src/test/java/com/vayunmathur/news/domain/SitemapParserTest.ktindex 123fbc3392..2cc059855d 100644--- a/news/src/test/java/com/vayunmathur/news/domain/SitemapParserTest.kt+++ b/news/src/test/java/com/vayunmathur/news/domain/SitemapParserTest.kt@@ -51,6 +51,48 @@ class SitemapParserTest {         assertTrue(parsed.articles[0].publishedAtMillis > 0L)     } +    @Test+    fun rdfRssItemsWithRdfAboutAttributeParse() {+        // RSS 1.0/RDF (e.g. tagesschau's newsticker.rdf, in the catalog):+        // every <item> carries an rdf:about attribute, and the channel+        // carries an <items> table of contents that is not an item.+        val xml = """+            <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"+                     xmlns:dc="http://purl.org/dc/elements/1.1/">+              <channel rdf:about="https://example.com/"><title>Example</title>+                <items><rdf:Seq><rdf:li rdf:resource="https://example.com/a"/></rdf:Seq></items>+              </channel>+              <item rdf:about="https://example.com/a"><title>Story A</title>+                <link>https://example.com/a</link><dc:date>2026-11-23T10:00:00Z</dc:date></item>+              <item rdf:about="https://example.com/b"><title>Story B</title>+                <link>https://example.com/b</link><dc:date>2026-11-23T09:00:00Z</dc:date></item>+            </rdf:RDF>+        """.trimIndent()+        val parsed = SitemapParser.parse(xml, "tagesschau")+        assertEquals(listOf("Story A", "Story B"), parsed.articles.map { it.title })+        assertEquals(+            listOf("https://example.com/a", "https://example.com/b"),+            parsed.articles.map { it.url },+        )+        assertTrue(parsed.articles.all { it.publishedAtMillis > 0L })+    }++    @Test+    fun atomEntriesWithAttributesParse() {+        val xml = """+            <feed xmlns="http://www.w3.org/2005/Atom">+              <entry xml:lang="en"><title>Atom Story</title>+                <link href="https://example.com/atom-a"/>+                <published>2026-11-23T10:00:00Z</published></entry>+            </feed>+        """.trimIndent()+        val parsed = SitemapParser.parse(xml, "ex")+        assertEquals(1, parsed.articles.size)+        assertEquals("Atom Story", parsed.articles[0].title)+        assertEquals("https://example.com/atom-a", parsed.articles[0].url)+        assertTrue(parsed.articles[0].publishedAtMillis > 0L)+    }+     @Test     fun bbcSizeUrlsetParsesWithinBound() {         // Regression for the 2026-11-23 ANR: the old whole-document regex