Rowan Collins
2010-Jun-20 00:50 UTC
[iCalendar-devel] Windows line endings not handled correctly
Hi, I''ve been using this library to re-encode some information from a 3rd-party API, and Google Calendar was failing to parse the results. I believe I''ve tracked down the problem to the handling of line endings when setting properties. Given the string "a\r\nb" as input, the output will be "a\r\\nb" - the CR is output literally, but the LF is escaped as ''\n''. An interpreter might consider the CR to be a newline, and the ''\n'' (since it is not indented) to be the next property in the file. The correct action in this example would be to escape the entire CRLF sequence as a single ''\n'', or more generally to normalise all line endings before encoding. It appears that VPIM has the same problem, but RiCal appears to handle this situation correctly. Example: require ''icalendar'' Icalendar::Calendar.new.tap{ |cal| cal.event do description "a\r\nb" end }.to_ical # => "BEGIN:VCALENDAR\r\nCALSCALE:GREGORIAN\r\nPRODID:iCalendar-Ruby\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nDESCRIPTION:a\r\\nb\r\nDTSTAMP:20100620T011601\r\nSEQUENCE:0\r\nUID:2010-06-20T01:16:01+01:00_969670122 at Norman\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" # should be # => "BEGIN:VCALENDAR\r\nCALSCALE:GREGORIAN\r\nPRODID:iCalendar-Ruby\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nDESCRIPTION:a\\nb\r\nDTSTAMP:20100620T011601\r\nSEQUENCE:0\r\nUID:2010-06-20T01:16:01+01:00_969670122 at Norman\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" Regards, Rowan Collins
Rowan Collins
2010-Jun-20 13:55 UTC
[iCalendar-devel] Windows line endings not handled correctly
Hi, Sorry to follow-up to my own post, but now it''s not so late at night, here''s a quick patch to fix the bug mentioned. Regards, Rowan Collins On 20/06/10 01:50, Rowan Collins wrote:> Hi, > > I''ve been using this library to re-encode some information from a > 3rd-party API, and Google Calendar was failing to parse the results. I > believe I''ve tracked down the problem to the handling of line endings > when setting properties. > > Given the string "a\r\nb" as input, the output will be "a\r\\nb" - the > CR is output literally, but the LF is escaped as ''\n''. An interpreter > might consider the CR to be a newline, and the ''\n'' (since it is not > indented) to be the next property in the file. > > The correct action in this example would be to escape the entire CRLF > sequence as a single ''\n'', or more generally to normalise all line > endings before encoding. > > It appears that VPIM has the same problem, but RiCal appears to handle > this situation correctly. > > Example: > > require ''icalendar'' > Icalendar::Calendar.new.tap{ |cal| cal.event do description "a\r\nb" > end }.to_ical > # => > "BEGIN:VCALENDAR\r\nCALSCALE:GREGORIAN\r\nPRODID:iCalendar-Ruby\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nDESCRIPTION:a\r\\nb\r\nDTSTAMP:20100620T011601\r\nSEQUENCE:0\r\nUID:2010-06-20T01:16:01+01:00_969670122 at Norman\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" > > > # should be > # => > "BEGIN:VCALENDAR\r\nCALSCALE:GREGORIAN\r\nPRODID:iCalendar-Ruby\r\nVERSION:2.0\r\nBEGIN:VEVENT\r\nDESCRIPTION:a\\nb\r\nDTSTAMP:20100620T011601\r\nSEQUENCE:0\r\nUID:2010-06-20T01:16:01+01:00_969670122 at Norman\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n" > > > Regards, > Rowan Collins-------------- next part -------------- A non-text attachment was scrubbed... Name: icalendar-line-endings.patch Type: text/x-patch Size: 589 bytes Desc: not available URL: <http://rubyforge.org/pipermail/icalendar-devel/attachments/20100620/c19a9ae3/attachment.bin>
Sean Dague
2010-Jun-21 13:32 UTC
[iCalendar-devel] Windows line endings not handled correctly
On 06/20/2010 09:55 AM, Rowan Collins wrote:> Hi, > > Sorry to follow-up to my own post, but now it''s not so late at night, > here''s a quick patch to fix the bug mentioned. > > Regards, > Rowan CollinsThank you for the bug and the fix. Patch applied and version 1.1.5 is now released with your changes included. -Sean -- __________________________________________________________________ Sean Dague Mid-Hudson Valley sean at dague dot net Linux Users Group http://dague.net http://mhvlug.org There is no silver bullet. Plus, werewolves make better neighbors than zombies, and they tend to keep the vampire population down. __________________________________________________________________ -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 190 bytes Desc: OpenPGP digital signature URL: <http://rubyforge.org/pipermail/icalendar-devel/attachments/20100621/9af31afd/attachment.bin>