fix: nbsp-Dekodierung + Malformed-Input-Test im Truth-Parser (Review Task 5)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
2026-06-12 08:09:35 +00:00
parent 71d07659e3
commit f0d4b6d566
2 changed files with 9 additions and 1 deletions

View File

@@ -15,6 +15,14 @@ describe('parseTruthFeed', () => {
expect(posts[0].text).toContain('Bitcoin is going to the MOON'); expect(posts[0].text).toContain('Bitcoin is going to the MOON');
expect(posts[0].text).not.toContain('<p>'); expect(posts[0].text).not.toContain('<p>');
}); });
test('überspringt malformed Items, leerer Input → []', () => {
expect(parseTruthFeed('')).toEqual([]);
const bad = `<rss><channel>
<item><pubDate>Fri, 12 Jun 2026 01:49:56 +0000</pubDate><description>ohne Link</description></item>
<item><link>https://trumpstruth.org/statuses/3</link><pubDate>kein Datum</pubDate><description>x</description></item>
</channel></rss>`;
expect(parseTruthFeed(bad)).toEqual([]);
});
}); });
describe('matchCoins', () => { describe('matchCoins', () => {

View File

@@ -21,7 +21,7 @@ export function parseTruthFeed(xml: string): TruthPost[] {
const text = descRaw const text = descRaw
.replace(/^<!\[CDATA\[|\]\]>$/g, '') .replace(/^<!\[CDATA\[|\]\]>$/g, '')
.replace(/<[^>]+>/g, ' ') .replace(/<[^>]+>/g, ' ')
.replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#39;/g, "'") .replace(/&amp;/g, '&').replace(/&lt;/g, '<').replace(/&gt;/g, '>').replace(/&quot;/g, '"').replace(/&#39;/g, "'").replace(/&nbsp;/g, ' ')
.replace(/\s+/g, ' ') .replace(/\s+/g, ' ')
.trim(); .trim();
posts.push({ url, ts, text }); posts.push({ url, ts, text });