rianjs / ical.net

ical.NET - an open source iCal library for .NET
MIT License
782 stars 230 forks source link

Deserialization fails if control characters are present in the Title / Description of the event #497

Open marius-bughiu opened 4 years ago

marius-bughiu commented 4 years ago

I am not entirely sure what exactly leads to this situation (whether it's the user doing something or some library serializing the events incorrectly), but I did manage to reproduce it using Outlook.com's web calendar. Simply create an event with  (U+0015 - negative acknowledge) as the title and send yourself an invite. The .ics file will contain the control character and the regex validation of the line will fail. Google seems to strip out these characters, though I have only tested with a few.

For now, I am removing all possibly offending control characters from the event before passing it to iCal.Net and that seems to work.

var controlCharactersRegex = new Regex("[\x00-\x08\x0E-\x1F\x7F]");
icsContents = controlCharactersRegex.Replace(icsContents, "");

return CalendarCollection.Load(icsContents);

For convenience, a sample file to reproduce the problem:

BEGIN:VCALENDAR
METHOD:REQUEST
BEGIN:VEVENT
UID:040000008200E00074C5B7101A82E00800000000A6129402D459D601000000000000000
 0100000008D3A0B17FB25644FA48A406BD593AC29
SUMMARY;LANGUAGE=en-US:
DTSTART;TZID=GTB Standard Time:20200714T170000
DTEND;TZID=GTB Standard Time:20200714T173000
DTSTAMP:20200714T114336Z
END:VEVENT
END:VCALENDAR