feat: normalize event text fields and show date range for multiday events#20
Conversation
…ayload handling ensureString only handled shallow objects with known keys (val, value, text) and fell back to String() which produced [object Object] for unknown shapes. normalizeEventText handles: - Nested objects recursively with a preferred-key priority list - Arrays (joins with ', ') - Circular reference detection via a seen-set - All render sites: title (previously unguarded), description, location - Uses textContent instead of innerHTML for safety
When showMultidayEventsOnce is true and event.isMultiday: - Fullday multiday: show date range (e.g. 'Apr 3 - Apr 9') using multidayRangeLabelOptions format - Timed multiday: show 'Apr 3 10:00 AM - Apr 9 2:00 PM' combining date and time for each endpoint Uses existing startTime/endTime CSS classes so the module stylesheet separator applies consistently. When showMultidayEventsOnce is false, behaviour is unchanged.
|
Backward compatibility note (re: The new MMM-CalendarExt3 calls const eDom = renderEventAgenda(event, options, moment)Why this lives in CX3_Shared and not in MMM-CalendarExt3Agenda's own scripts: The multiday time display is built entirely inside The new behavior only activates when a consuming module explicitly passes |
Remove 'description', 'location', and 'html' from the preferred key
list, and add the missing 'title'.
'description' and 'location' are event-level fields, not generic
text-container properties. Including them as preferred keys means any
object that happens to have a 'description' key would have its
description extracted instead of its actual text value — wrong
semantics.
'html' would pass raw markup through to textContent, rendering tag
literals visibly in the UI.
'title' was the obvious gap: a common iCal object shape is
{title: "…"} which previously fell through to the flattening
fallback instead of being extracted directly.
|
Thanks! I'm building a new release :-) |
Summary
Replaces the shallow
ensureStringhelper with a recursivenormalizeEventTextfunction that safely handles nested objects, arrays, and circular references — covering all event text fields includingtitle, which was previously unguarded.Also changes
innerHTMLassignments fordescriptionandlocationtotextContentto prevent XSS from malformed calendar payloads.Problem
Some calendar providers (e.g. certain Outlook/iCloud payloads) wrap event fields in nested objects, yielding
[object Object]when stringified. The oldensureStringonly handled description and location, and was not recursive. Eventtitlehad no protection.Changes
ensureStringwithnormalizeEventText(val, depth=0):null/undefined→"",value,text,name,title) for plain objects beforeJSON.stringifyfallbacknormalizeEventTexttotitle,description, andlocationinrenderEvent,renderEventJournal, andrenderEventAgendae.dataset.titledescriptionandlocationrender sites frominnerHTMLtotextContent