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:
parent
848cdf763e
commit
715c1f5e1e
|
|
@ -38,7 +38,9 @@ function tagValue(ev: SignedEvent, name: string): string | undefined {
|
||||||
}
|
}
|
||||||
|
|
||||||
function tagsAll(ev: SignedEvent, name: string): string[] {
|
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 {
|
function deriveSummary(content: string): string {
|
||||||
|
|
|
||||||
|
|
@ -81,3 +81,19 @@ Deno.test('buildPostJson: lang default de wenn keine l-tags', () => {
|
||||||
const json = buildPostJson(ev, new Map())
|
const json = buildPostJson(ev, new Map())
|
||||||
assertEquals(json.lang, 'de')
|
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'])
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue