feat: harden RSS source fetching

This commit is contained in:
2026-07-19 12:38:43 +08:00
parent 782f7988f1
commit 3fc274e9f1
3 changed files with 47 additions and 5 deletions
+11
View File
@@ -0,0 +1,11 @@
import assert from "node:assert/strict";
import { test } from "node:test";
import { parseFeed } from "../lib/rss";
test("parses RSS and Atom items without evaluating XML declarations", () => {
const rss = parseFeed("<rss><channel><item><guid>one</guid><link>https://example.test/one</link><description><![CDATA[Hello]]></description><pubDate>2026-07-19T00:00:00Z</pubDate></item></channel></rss>");
assert.deepEqual(rss[0], { id: "one", link: "https://example.test/one", content: "Hello", publishedAt: "2026-07-19T00:00:00.000Z" });
const atom = parseFeed("<feed><entry><id>two</id><link href=\"https://example.test/two\"/><summary>World</summary><updated>2026-07-19T01:00:00Z</updated></entry></feed>");
assert.deepEqual(atom[0], { id: "two", link: "https://example.test/two", content: "World", publishedAt: "2026-07-19T01:00:00.000Z" });
assert.throws(() => parseFeed("<!DOCTYPE feed><feed />"), /unsupported XML/);
});