Revision: 2260
          http://mrbs.svn.sourceforge.net/mrbs/?rev=2260&view=rev
Author:   cimorrison
Date:     2012-01-27 15:57:34 +0000 (Fri, 27 Jan 2012)
Log Message:
-----------
Added improving parsing of iCalendar lines to ignore delimiters inside quoted 
strings.   Thanks to John Beranek.

Modified Paths:
--------------
    mrbs/branches/ics_import/web/functions_ical.inc

Modified: mrbs/branches/ics_import/web/functions_ical.inc
===================================================================
--- mrbs/branches/ics_import/web/functions_ical.inc     2012-01-27 12:03:29 UTC 
(rev 2259)
+++ mrbs/branches/ics_import/web/functions_ical.inc     2012-01-27 15:57:34 UTC 
(rev 2260)
@@ -588,6 +588,25 @@
 }
 
 
+// Splits a string at the first colon or semicolon (the delimiter) unless the 
delimiter
+// is inside a quoted string.  Used for parsing iCalendar lines to get 
property parameters
+// It assumes the string will always have at least one more delimiter to come, 
so can 
+// only be used when you know you've still got the colon to come.
+//
+// Returns an array of three elements (the second is the delimiter)
+// or just one element if the delimiter is not found
+function ical_split($string)
+{
+  // We want to split the string up to the first delimiter whch isn't inside a 
quoted
+  // string.   So the look ahead must not contain exactly one double quote 
before the next
+  // delimiter.   Note that (a) you cannot escape double quotes inside a 
quoted string, so we
+  // we don't have to worry about that complication (b) we assume there will 
always be a
+  // second delimiter
+  return preg_split('/([:;](?![^"]*"{1}[:;]))/', $string, 2, 
PREG_SPLIT_DELIM_CAPTURE);
+}
+
+
+
 // Parse a content line which is a property (ie is inside a component).   
Returns
 // an associative array:
 //   'name'       the property name
@@ -601,7 +620,7 @@
   // whether there are any parameters to come.   The split will return an array
   // with three elements:  0 - the string before the delimiter, 1 - the 
delimiter
   // and 2 the rest of the string
-  $tmp = preg_split('/([;:])/' , $line, 2, PREG_SPLIT_DELIM_CAPTURE);
+  $tmp = ical_split($line);
   $result['name'] = $tmp[0];
   $params = array();
   if ($tmp[1] != ':')
@@ -609,7 +628,7 @@
     // Get all the property parameters
     do 
     {
-      $tmp = preg_split('/([;:])/' , $tmp[2], 2, PREG_SPLIT_DELIM_CAPTURE);
+      $tmp = ical_split($tmp[2]);
       list($param_name, $param_value) = explode('=', $tmp[0], 2);
       // The parameter value can be a quoted string, so get rid of any double 
quotes
       $params[$param_name] = ical_unescape_quoted_string($param_value);

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Mrbs-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mrbs-commits

Reply via email to