--- ical.inc-old	2006-05-08 21:24:52.000000000 +0200
+++ ical.inc	2006-05-08 21:58:24.000000000 +0200
@@ -51,8 +51,8 @@ function ical_export($events, $calname =
     else if ($event['start']) {
       $output .= "DTSTART;VALUE=DATE-TIME:" . gmdate("Ymd\THis\Z", $event['start']) . "\n";
     }
-    $output .= "SUMMARY:" . $event['summary'] . "\n";
-    if ($event['description']) $output .= "DESCRIPTION:" . str_replace("\n", "\n ", strip_tags($event['description'])) . "\n";
+    $output .= "SUMMARY:" . ical_escape_text($event['summary']) . "\n";
+    if ($event['description']) $output .= "DESCRIPTION:" . ical_escape_text($event['description']) . "\n";
     if ($event['url']) $output .= "URL;VALUE=URI:" . $event['url'] . "\n";
     if ($event['location']) $output .= "LOCATION:" . $event['location'] . "\n";
     $output .= "UID:" . ($event['uid'] ? $event['uid'] : $uid) . "\n";
@@ -62,6 +62,27 @@ function ical_export($events, $calname =
   return $output;
 }
 
+/**
+ * Escape #text elements for safe iCal use
+ *
+ * @param $text
+ *   Text to escape
+ *
+ * @return
+ *   Escaped text
+ *
+ */
+function ical_escape_text($text) {
+  $text = strip_tags($text);
+  $text = str_replace('"', '\"', $text);
+  $text = str_replace("\\", "\\\\", $text);
+  $text = str_replace(",", "\,", $text);
+  $text = str_replace(":", "\":\"", $text);
+  $text = str_replace(";", "\;", $text);
+  $text = str_replace("\n", "\n ", $text);
+  return $text;
+}
+
 /**                                                                                                                                                                   
  * Given the location of a valide iCalendar file, will return an array of event information
  *
