Bug 1553820 - Update libical from upstream. r=philipp
authorluis.merino@x41-dsec.de
Fri, 31 May 2019 23:13:54 +0300
changeset 35828 bab0908888b8a7f8399a440bbc345b3d895d68c4
parent 35827 9605974b295d9fc51e196c928ff9895818efd398
child 35829 e48bbc985397423402a45e5fbf0b63b46e7470cf
push id392
push userclokep@gmail.com
push dateMon, 02 Sep 2019 20:17:19 +0000
reviewersphilipp
bugs1553820
Bug 1553820 - Update libical from upstream. r=philipp Like https://github.com/libical/libical/blame/e84714e9d6ec724dca889531e11fb963cadc2dba/src/libical/icalparser.c#L147
calendar/libical/src/libical/icalparser.c
--- a/calendar/libical/src/libical/icalparser.c
+++ b/calendar/libical/src/libical/icalparser.c
@@ -185,35 +185,34 @@ icalvalue* icalvalue_new_From_string_wit
                                                 char* str, 
                                                 icalproperty **error);
 
 
 static
 char* parser_get_next_char(char c, char *str, int qm)
 {
     int quote_mode = 0;
-    char* p;
-
-    for(p=str; *p!=0; p++){
-	    if (qm == 1) {
-				if ( quote_mode == 0 && *p=='"' && *(p-1) != '\\' ){
-						quote_mode =1;
-						continue;
-				}
+    char *p = str;
+    char next_char = *p;
+    char prev_char = 0;
 
-				if ( quote_mode == 1 && *p=='"' && *(p-1) != '\\' ){
-						quote_mode =0;
-						continue;
-				}
-	    }
-		
-		if (quote_mode == 0 &&  *p== c  && *(p-1) != '\\' ){
-				return p;
-		} 
+    while (next_char != '\0') {
+        if (prev_char != '\\') {
+            if (qm == 1 && next_char == '"') {
+                /* Encountered a quote, toggle quote mode */
+                quote_mode = !quote_mode;
+            } else if (quote_mode == 0 && next_char == c) {
+                /* Found a matching character out of quote mode, return it */
+                return p;
+            }
+        }
 
+        /* Save the previous character so we can check if it's a backslash in the next iteration */
+        prev_char = next_char;
+        next_char = *(++p);
     }
 
     return 0;
 }
 
 
 /** make a new tmp buffer out of a substring */
 static char* make_segment(char* start, char* end)