From 715c1f5e1e92b9c395ae508e89fd3772d8d16ce7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lohrer?= Date: Tue, 28 Apr 2026 08:19:51 +0200 Subject: [PATCH] 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) --- snapshot/src/core/post-json.ts | 4 +++- snapshot/tests/post-json.test.ts | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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']) +})