From 3c909091592ae4b55d5a54338fb572f5724caf28 Mon Sep 17 00:00:00 2001 From: znek Date: Wed, 20 Oct 2004 12:13:04 +0000 Subject: [PATCH] improved robustness git-svn-id: http://svn.opengroupware.org/SOPE/trunk@283 e4a50df8-12e2-0310-a44c-efbce7f8a7e3 --- sope-ical/versitSaxDriver/ChangeLog | 7 +++ sope-ical/versitSaxDriver/VSSaxDriver.m | 71 +++++++++++++++++++++++-- sope-ical/versitSaxDriver/Version | 2 +- 3 files changed, 76 insertions(+), 4 deletions(-) diff --git a/sope-ical/versitSaxDriver/ChangeLog b/sope-ical/versitSaxDriver/ChangeLog index 54c70c66..c6204244 100644 --- a/sope-ical/versitSaxDriver/ChangeLog +++ b/sope-ical/versitSaxDriver/ChangeLog @@ -1,3 +1,10 @@ +2004-10-20 Marcus Mueller + + * VSSaxDriver.m: remove surrounding double quotes from attribute values + if any. During parsing, check if end tags match expectations and + issue warnings if they don't. Added some logic to get parsing + straight nevertheless in such events. (v4.3.10) + 2004-10-19 Marcus Mueller * v4.3.9 diff --git a/sope-ical/versitSaxDriver/VSSaxDriver.m b/sope-ical/versitSaxDriver/VSSaxDriver.m index 230594d4..203bd9e9 100644 --- a/sope-ical/versitSaxDriver/VSSaxDriver.m +++ b/sope-ical/versitSaxDriver/VSSaxDriver.m @@ -248,8 +248,26 @@ static VSStringFormatter *stringFormatter = nil; r = [_attr rangeOfCharacterFromSet:equalSignCharSet]; if (r.length > 0) { + unsigned left, right; + attrName = [[_attr substringToIndex:r.location] uppercaseString]; - attrValue = [_attr substringFromIndex:(r.location + 1)]; + left = NSMaxRange(r); + right = [_attr length] - 1; + if(left != right) { + if(([_attr characterAtIndex:left] == '"') && + ([_attr characterAtIndex:right] == '"')) + { + left += 1; + r = NSMakeRange(left, right - left); + attrValue = [_attr substringWithRange:r]; + } + else { + attrValue = [_attr substringFromIndex:left]; + } + } + else { + attrValue = @""; + } } else { attrName = @"TYPE"; @@ -420,6 +438,7 @@ static VSStringFormatter *stringFormatter = nil; r = [_line rangeOfCharacterFromSet:colonAndSemicolonCharSet options:0 range:todoRange]; + /* is line well-formed? */ if(r.length == 0) { if(debugOn) { NSLog(@"%s got an improper content line! ->\n%@", @@ -432,6 +451,9 @@ static VSStringFormatter *stringFormatter = nil; tagName = [[_line substringToIndex:r.location] uppercaseString]; tagAttributes = [[NSMutableArray alloc] init]; + /* possible shortcut: if we spotted a ':', we don't have to do "expensive" + argument scanning/processing. + */ if([_line characterAtIndex:r.location] != ':') { BOOL isAtEnd = NO, isInDquote = NO; unsigned start = NSMaxRange(r); @@ -444,7 +466,7 @@ static VSStringFormatter *stringFormatter = nil; r = [_line rangeOfCharacterFromSet:colonSemicolonAndDquoteCharSet options:0 range:todoRange]; - /* is line well-formed ? */ + /* is line well-formed? */ if(r.length == 0 || r.location == 0) { if(debugOn) { NSLog(@"%s got an improper content line! ->\n%@", @@ -498,7 +520,41 @@ static VSStringFormatter *stringFormatter = nil; [self->cardStack addObject:tag]; } else if ([tagName isEqualToString:@"END"]) { - [self _endTag:[self _mapTagName:tagValue]]; + NSString *mtName; + + mtName = [self _mapTagName:tagValue]; + if([self->cardStack count] > 0) { + NSString *expectedName; + + expectedName = [[self->cardStack lastObject] objectAtIndex:1]; + if(![expectedName isEqualToString:mtName]) { + if(debugOn) { + NSLog(@"%s found end tag '%@' which doesn't match expected name " + @"'%@'! Tag '%@' hasn't been closed properly. Given iCal " + @"document contains errors!", + __PRETTY_FUNCTION__, + mtName, + expectedName, + expectedName); + } + /* probably futile attempt to parse anyways */ + if(debugOn) { + NSLog(@"%s trying to fix previous error by inserting bogus end " + @"tag.", + __PRETTY_FUNCTION__); + } + [self _endTag:expectedName]; + [self->cardStack removeLastObject]; + } + } + else { + if(debugOn) { + NSLog(@"%s found end tag '%@' without any open tags left?!", + __PRETTY_FUNCTION__, + mtName); + } + } + [self _endTag:mtName]; [self->cardStack removeLastObject]; if ([self->cardStack count] == 0) [self _eventsForElements]; @@ -613,6 +669,15 @@ static VSStringFormatter *stringFormatter = nil; [self _parseLine:line]; } + if([self->cardStack count] != 0) { + if(debugOn) { + NSLog(@"%s found elements on cardStack. This indicates an improper " + @"iCal structure! Not all required events will have been " + @"generated, leading to unpredictable results!", + __PRETTY_FUNCTION__); + } + } + [line release]; [self->contentHandler endPrefixMapping:@""]; [self->contentHandler endDocument]; diff --git a/sope-ical/versitSaxDriver/Version b/sope-ical/versitSaxDriver/Version index b191a15e..c7825e07 100644 --- a/sope-ical/versitSaxDriver/Version +++ b/sope-ical/versitSaxDriver/Version @@ -1,3 +1,3 @@ # Version file -SUBMINOR_VERSION:=9 +SUBMINOR_VERSION:=10 -- 2.39.5