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:
parent
124cad1249
commit
9ac31de49f
1 changed files with 9 additions and 1 deletions
|
|
@ -181,6 +181,14 @@ export function parseCalendarDateEvent(event: NostrEvent): CalendarDateEvent | n
|
||||||
|
|
||||||
if (!dTag || !title || !start) return null
|
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
|
const participants: Participant[] = event.tags
|
||||||
.filter(t => t[0] === 'p')
|
.filter(t => t[0] === 'p')
|
||||||
.map(t => ({
|
.map(t => ({
|
||||||
|
|
@ -197,7 +205,7 @@ export function parseCalendarDateEvent(event: NostrEvent): CalendarDateEvent | n
|
||||||
content: event.content,
|
content: event.content,
|
||||||
image: getTagValue(event.tags, 'image'),
|
image: getTagValue(event.tags, 'image'),
|
||||||
start,
|
start,
|
||||||
end: getTagValue(event.tags, 'end'),
|
end,
|
||||||
location: getTagValue(event.tags, 'location'),
|
location: getTagValue(event.tags, 'location'),
|
||||||
geohash: getTagValue(event.tags, 'g'),
|
geohash: getTagValue(event.tags, 'g'),
|
||||||
hashtags: getTagValues(event.tags, 't'),
|
hashtags: getTagValues(event.tags, 't'),
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue