diff --git a/snapshot/src/core/post-json.ts b/snapshot/src/core/post-json.ts index b28e510..994bfb9 100644 --- a/snapshot/src/core/post-json.ts +++ b/snapshot/src/core/post-json.ts @@ -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 { diff --git a/snapshot/tests/post-json.test.ts b/snapshot/tests/post-json.test.ts index 1d2b89b..e22043b 100644 --- a/snapshot/tests/post-json.test.ts +++ b/snapshot/tests/post-json.test.ts @@ -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']) +})