fix(snapshot): tagsAll filtert tags ohne value

Vorher konnten malformed tags wie ['t'] (ohne second element)
undefined ins string[]-array werfen, das im JSON als null landete.
Code-review-feedback aus etappe 2.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jörg Lohrer 2026-04-28 08:19:51 +02:00
parent 848cdf763e
commit 715c1f5e1e
2 changed files with 19 additions and 1 deletions

View File

@ -38,7 +38,9 @@ function tagValue(ev: SignedEvent, name: string): string | undefined {
}
function tagsAll(ev: SignedEvent, name: string): string[] {
return ev.tags.filter((t) => t[0] === name).map((t) => t[1])
return ev.tags
.filter((t) => t[0] === name && typeof t[1] === 'string')
.map((t) => t[1] as string)
}
function deriveSummary(content: string): string {

View File

@ -81,3 +81,19 @@ Deno.test('buildPostJson: lang default de wenn keine l-tags', () => {
const json = buildPostJson(ev, new Map())
assertEquals(json.lang, 'de')
})
Deno.test('buildPostJson: malformed t-tag ohne value wird ignoriert', () => {
const ev: SignedEvent = {
id: 'event-malformed', pubkey: PUBKEY, created_at: 1700000000, kind: 30023,
sig: 'sig', content: 'x',
tags: [
['d', 'malformed'],
['title', 'X'],
['t', 'gut'],
['t'], // malformed: kein value
['t', 'auch-gut'],
],
}
const json = buildPostJson(ev, new Map())
assertEquals(json.tags, ['gut', 'auch-gut'])
})