From 0daba4888771e29f2edf170216adaf3d33040bea Mon Sep 17 00:00:00 2001 From: Ulf Jasper Date: Sat, 5 Dec 2015 16:55:49 +0100 Subject: [PATCH] Fix Bug#22092. * lisp/calendar/icalendar.el (icalendar--get-unfolded-buffer): Clean up inconsistent line endings. (Bug#22092) (icalendar--clean-up-line-endings): New. * test/automated/icalendar-tests.el (icalendar-real-world): Add test for Bug#22092. --- lisp/calendar/icalendar.el | 13 ++++++- test/automated/icalendar-tests.el | 56 +++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) diff --git a/lisp/calendar/icalendar.el b/lisp/calendar/icalendar.el index 0c7a0636b08..ca6669d0c40 100644 --- a/lisp/calendar/icalendar.el +++ b/lisp/calendar/icalendar.el @@ -321,18 +321,29 @@ other sexp entries are enumerated in any case." "Return a new buffer containing the unfolded contents of a buffer. Folding is the iCalendar way of wrapping long lines. In the created buffer all occurrences of CR LF BLANK are replaced by the -empty string. Argument FOLDED-ICAL-BUFFER is the unfolded input +empty string. Argument FOLDED-ICAL-BUFFER is the folded input buffer." (let ((unfolded-buffer (get-buffer-create " *icalendar-work*"))) (save-current-buffer (set-buffer unfolded-buffer) (erase-buffer) (insert-buffer-substring folded-ical-buffer) + (icalendar--clean-up-line-endings) (goto-char (point-min)) (while (re-search-forward "\r?\n[ \t]" nil t) (replace-match "" nil nil))) unfolded-buffer)) +(defun icalendar--clean-up-line-endings () + "Replace DOS- and MAC-like line endings with unix line endings. +All occurrences of (CR LF) and (LF CF) are replaced with LF in +the current buffer. This is necessary in buffers which contain a +mix of different line endings." + (save-excursion + (goto-char (point-min)) + (while (re-search-forward "\r\n\\|\n\r" nil t) + (replace-match "\n" nil nil)))) + (defsubst icalendar--rris (regexp rep string &optional fixedcase literal) "Replace regular expression in string. Pass arguments REGEXP REP STRING FIXEDCASE LITERAL to diff --git a/test/automated/icalendar-tests.el b/test/automated/icalendar-tests.el index 7e05d49883e..829cbf2d765 100644 --- a/test/automated/icalendar-tests.el +++ b/test/automated/icalendar-tests.el @@ -2231,7 +2231,63 @@ END:VCALENDAR" Class: PUBLIC UID: 040000008200E00074C5B7101A82E0080000000020FFAED0CFEFCC01000000000000000010000000575268034ECDB649A15349B1BF240F15 " nil) + + ;; 2015-12-05, mixed line endings and empty lines, see Bug#22092. + (icalendar-tests--test-import + "BEGIN:VCALENDAR\r +PRODID:-//www.norwegian.no//iCalendar MIMEDIR//EN\r +VERSION:2.0\r +METHOD:REQUEST\r +BEGIN:VEVENT\r +UID:RFCALITEM1\r +SEQUENCE:1512040950\r +DTSTAMP:20141204T095043Z\r +ORGANIZER:noreply@norwegian.no\r +DTSTART:20141208T173000Z\r + +DTEND:20141208T215500Z\r + +LOCATION:Stavanger-Sola\r + +DESCRIPTION:Fly med Norwegian, reservasjon. Fra Stavanger til Tromsø 8. des 2014 18:30, DY545Fly med Norwegian, reservasjon . Fra Stavanger til Tromsø 8. des 2014 21:00, DY390\r + +X-ALT-DESC;FMTTYPE=text/html:Reisereferanse

+SUMMARY:Norwegian til Tromsoe-Langnes -\r + +CATEGORIES:Appointment\r + + +PRIORITY:5\r + +CLASS:PUBLIC\r + +TRANSP:OPAQUE\r +END:VEVENT\r +END:VCALENDAR +" +"&2014/12/8 18:30-22:55 Norwegian til Tromsoe-Langnes - + Desc: Fly med Norwegian, reservasjon. Fra Stavanger til Tromsø 8. des 2014 18:30, DY545Fly med Norwegian, reservasjon . Fra Stavanger til Tromsø 8. des 2014 21:00, DY390 + Location: Stavanger-Sola + Organizer: noreply@norwegian.no + Class: PUBLIC + UID: RFCALITEM1 +" +"&8/12/2014 18:30-22:55 Norwegian til Tromsoe-Langnes - + Desc: Fly med Norwegian, reservasjon. Fra Stavanger til Tromsø 8. des 2014 18:30, DY545Fly med Norwegian, reservasjon . Fra Stavanger til Tromsø 8. des 2014 21:00, DY390 + Location: Stavanger-Sola + Organizer: noreply@norwegian.no + Class: PUBLIC + UID: RFCALITEM1 +" +"&12/8/2014 18:30-22:55 Norwegian til Tromsoe-Langnes - + Desc: Fly med Norwegian, reservasjon. Fra Stavanger til Tromsø 8. des 2014 18:30, DY545Fly med Norwegian, reservasjon . Fra Stavanger til Tromsø 8. des 2014 21:00, DY390 + Location: Stavanger-Sola + Organizer: noreply@norwegian.no + Class: PUBLIC + UID: RFCALITEM1 +" ) + ) (provide 'icalendar-tests) ;;; icalendar-tests.el ends here -- 2.39.2