Question

Photo of Ben Goshow

0

Apostrophe in Event Name breaks ICS link

What filter should I use to escape the apostrophe in an event title like this? The JavaScript console error shows `Uncaught SyntaxError: missing ) after argument list`

Image 2019-04-10 at 10.59.19 AM.png

  • Photo of Dennis OFlynn

    1

    Ben,

    The Event Details is provided by the block Calendar Event Item Occurrence Lava block.  This block includes the Lava script CalendarItem.lava to format the event details, including the link to ICS.

    Within the lava script, the ics_click() function is defined that references several event attributes.  

    <script>function ics_click() { text = `{{ EventItemOccurrence.Schedule.iCalendarContent }}`.replace('END:VEVENT', 'SUMMARY: {{ Event.Name }}\r\nLOCATION: {{ EventItemOccurrence.Location }}\r\nEND:VEVENT'); var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', '{{ Event.Name }}.ics'); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); }</script>
    

    Some of these event attributes should be referenced using the Lava Text Filter Escape so that the apostrophe (') is properly passed to the JavaScript function.

    <script>function ics_click() { text = `{{ EventItemOccurrence.Schedule.iCalendarContent }}`.replace('END:VEVENT', 'SUMMARY: {{ Event.Name | Escape }}\r\nLOCATION: {{ EventItemOccurrence.Location | Escape }}\r\nEND:VEVENT'); var element = document.createElement('a'); element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text)); element.setAttribute('download', '{{ Event.Name | Escape }}.ics'); element.style.display = 'none'; document.body.appendChild(element); element.click(); document.body.removeChild(element); }</script>
    

    I suggest you submit a bug report on this issue.

    An easy workaround is to modify the lava script to properly escape the event attributes.