diff options
| author | Ulf Jasper | 2015-12-05 16:55:49 +0100 |
|---|---|---|
| committer | Ulf Jasper | 2015-12-05 17:00:44 +0100 |
| commit | 0daba4888771e29f2edf170216adaf3d33040bea (patch) | |
| tree | ec8f5223cc06b8773bca95ac42c4194ec53a612a | |
| parent | 21c042bc6d42ad0d1562a1ac259025b72fcd4e3c (diff) | |
| download | emacs-0daba4888771e29f2edf170216adaf3d33040bea.tar.gz emacs-0daba4888771e29f2edf170216adaf3d33040bea.zip | |
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.
| -rw-r--r-- | lisp/calendar/icalendar.el | 13 | ||||
| -rw-r--r-- | test/automated/icalendar-tests.el | 56 |
2 files changed, 68 insertions, 1 deletions
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." | |||
| 321 | "Return a new buffer containing the unfolded contents of a buffer. | 321 | "Return a new buffer containing the unfolded contents of a buffer. |
| 322 | Folding is the iCalendar way of wrapping long lines. In the | 322 | Folding is the iCalendar way of wrapping long lines. In the |
| 323 | created buffer all occurrences of CR LF BLANK are replaced by the | 323 | created buffer all occurrences of CR LF BLANK are replaced by the |
| 324 | empty string. Argument FOLDED-ICAL-BUFFER is the unfolded input | 324 | empty string. Argument FOLDED-ICAL-BUFFER is the folded input |
| 325 | buffer." | 325 | buffer." |
| 326 | (let ((unfolded-buffer (get-buffer-create " *icalendar-work*"))) | 326 | (let ((unfolded-buffer (get-buffer-create " *icalendar-work*"))) |
| 327 | (save-current-buffer | 327 | (save-current-buffer |
| 328 | (set-buffer unfolded-buffer) | 328 | (set-buffer unfolded-buffer) |
| 329 | (erase-buffer) | 329 | (erase-buffer) |
| 330 | (insert-buffer-substring folded-ical-buffer) | 330 | (insert-buffer-substring folded-ical-buffer) |
| 331 | (icalendar--clean-up-line-endings) | ||
| 331 | (goto-char (point-min)) | 332 | (goto-char (point-min)) |
| 332 | (while (re-search-forward "\r?\n[ \t]" nil t) | 333 | (while (re-search-forward "\r?\n[ \t]" nil t) |
| 333 | (replace-match "" nil nil))) | 334 | (replace-match "" nil nil))) |
| 334 | unfolded-buffer)) | 335 | unfolded-buffer)) |
| 335 | 336 | ||
| 337 | (defun icalendar--clean-up-line-endings () | ||
| 338 | "Replace DOS- and MAC-like line endings with unix line endings. | ||
| 339 | All occurrences of (CR LF) and (LF CF) are replaced with LF in | ||
| 340 | the current buffer. This is necessary in buffers which contain a | ||
| 341 | mix of different line endings." | ||
| 342 | (save-excursion | ||
| 343 | (goto-char (point-min)) | ||
| 344 | (while (re-search-forward "\r\n\\|\n\r" nil t) | ||
| 345 | (replace-match "\n" nil nil)))) | ||
| 346 | |||
| 336 | (defsubst icalendar--rris (regexp rep string &optional fixedcase literal) | 347 | (defsubst icalendar--rris (regexp rep string &optional fixedcase literal) |
| 337 | "Replace regular expression in string. | 348 | "Replace regular expression in string. |
| 338 | Pass arguments REGEXP REP STRING FIXEDCASE LITERAL to | 349 | 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" | |||
| 2231 | Class: PUBLIC | 2231 | Class: PUBLIC |
| 2232 | UID: 040000008200E00074C5B7101A82E0080000000020FFAED0CFEFCC01000000000000000010000000575268034ECDB649A15349B1BF240F15 | 2232 | UID: 040000008200E00074C5B7101A82E0080000000020FFAED0CFEFCC01000000000000000010000000575268034ECDB649A15349B1BF240F15 |
| 2233 | " nil) | 2233 | " nil) |
| 2234 | |||
| 2235 | ;; 2015-12-05, mixed line endings and empty lines, see Bug#22092. | ||
| 2236 | (icalendar-tests--test-import | ||
| 2237 | "BEGIN:VCALENDAR\r | ||
| 2238 | PRODID:-//www.norwegian.no//iCalendar MIMEDIR//EN\r | ||
| 2239 | VERSION:2.0\r | ||
| 2240 | METHOD:REQUEST\r | ||
| 2241 | BEGIN:VEVENT\r | ||
| 2242 | UID:RFCALITEM1\r | ||
| 2243 | SEQUENCE:1512040950\r | ||
| 2244 | DTSTAMP:20141204T095043Z\r | ||
| 2245 | ORGANIZER:noreply@norwegian.no\r | ||
| 2246 | DTSTART:20141208T173000Z\r | ||
| 2247 | |||
| 2248 | DTEND:20141208T215500Z\r | ||
| 2249 | |||
| 2250 | LOCATION:Stavanger-Sola\r | ||
| 2251 | |||
| 2252 | 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 | ||
| 2253 | |||
| 2254 | X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\"><html><head><META NAME=\"Generator\" CONTENT=\"MS Exchange Server version 08.00.0681.000\"><title></title></head><body><b><font face=\"Calibri\" size=\"3\">Reisereferanse</p></body></html> | ||
| 2255 | SUMMARY:Norwegian til Tromsoe-Langnes -\r | ||
| 2256 | |||
| 2257 | CATEGORIES:Appointment\r | ||
| 2258 | |||
| 2259 | |||
| 2260 | PRIORITY:5\r | ||
| 2261 | |||
| 2262 | CLASS:PUBLIC\r | ||
| 2263 | |||
| 2264 | TRANSP:OPAQUE\r | ||
| 2265 | END:VEVENT\r | ||
| 2266 | END:VCALENDAR | ||
| 2267 | " | ||
| 2268 | "&2014/12/8 18:30-22:55 Norwegian til Tromsoe-Langnes - | ||
| 2269 | 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 | ||
| 2270 | Location: Stavanger-Sola | ||
| 2271 | Organizer: noreply@norwegian.no | ||
| 2272 | Class: PUBLIC | ||
| 2273 | UID: RFCALITEM1 | ||
| 2274 | " | ||
| 2275 | "&8/12/2014 18:30-22:55 Norwegian til Tromsoe-Langnes - | ||
| 2276 | 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 | ||
| 2277 | Location: Stavanger-Sola | ||
| 2278 | Organizer: noreply@norwegian.no | ||
| 2279 | Class: PUBLIC | ||
| 2280 | UID: RFCALITEM1 | ||
| 2281 | " | ||
| 2282 | "&12/8/2014 18:30-22:55 Norwegian til Tromsoe-Langnes - | ||
| 2283 | 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 | ||
| 2284 | Location: Stavanger-Sola | ||
| 2285 | Organizer: noreply@norwegian.no | ||
| 2286 | Class: PUBLIC | ||
| 2287 | UID: RFCALITEM1 | ||
| 2288 | " | ||
| 2234 | ) | 2289 | ) |
| 2290 | ) | ||
| 2235 | 2291 | ||
| 2236 | (provide 'icalendar-tests) | 2292 | (provide 'icalendar-tests) |
| 2237 | ;;; icalendar-tests.el ends here | 2293 | ;;; icalendar-tests.el ends here |