fix(activities): reject malformed NIP-52 kind 31922 events at parse time

parseCalendarDateEvent accepted any non-empty `start` string, letting
events with embedded times (e.g. "2026-05-25T10:00") through. Downstream
parseIsoDate then split on "-" and produced an Invalid Date, crashing
the renderer with "RangeError: Invalid time value".

Validate `start` and `end` against YYYY-MM-DD at parse time so bad events
are dropped before reaching the view — symmetric with how the time-event
parser rejects unparseable timestamps.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Padreug 2026-05-20 01:24:01 +02:00
commit 9ac31de49f

View file

@ -181,6 +181,14 @@ export function parseCalendarDateEvent(event: NostrEvent): CalendarDateEvent | n
if (!dTag || !title || !start) return null
// NIP-52 kind 31922 requires YYYY-MM-DD. Reject anything else (including
// accidentally-published datetimes) so downstream parseIsoDate cannot
// produce an Invalid Date and crash the renderer.
const ISO_DATE = /^\d{4}-\d{2}-\d{2}$/
if (!ISO_DATE.test(start)) return null
const end = getTagValue(event.tags, 'end')
if (end && !ISO_DATE.test(end)) return null
const participants: Participant[] = event.tags
.filter(t => t[0] === 'p')
.map(t => ({
@ -197,7 +205,7 @@ export function parseCalendarDateEvent(event: NostrEvent): CalendarDateEvent | n
content: event.content,
image: getTagValue(event.tags, 'image'),
start,
end: getTagValue(event.tags, 'end'),
end,
location: getTagValue(event.tags, 'location'),
geohash: getTagValue(event.tags, 'g'),
hashtags: getTagValues(event.tags, 't'),