Skip to content

Commit

Permalink
Merge pull request #5 from OutSystems/fix/RNMT-3533/crash-nspredicate
Browse files Browse the repository at this point in the history
RNMT-3533 Calendar Plugin ::: Crash when deleting event when special characters are used in the search NSPredicate
  • Loading branch information
usernuno authored Nov 7, 2019
2 parents 55b9253 + 93494d8 commit 6149d3f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/ios/Calendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -303,17 +303,19 @@ - (NSArray*) findEKEventsWithTitle: (NSString *)title
calendars: (NSArray*)calendars {

NSMutableArray *predicateStrings = [NSMutableArray arrayWithCapacity:3];
NSMutableArray *predicateArguments = [NSMutableArray arrayWithCapacity:3];

if (title != (id)[NSNull null] && title.length > 0) {
title = [title stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
[predicateStrings addObject:[NSString stringWithFormat:@"title contains[c] '%@'", title]];
[predicateStrings addObject:@"title contains[c] %@"];
[predicateArguments addObject:title];
}
if (location != (id)[NSNull null] && location.length > 0) {
location = [location stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
[predicateStrings addObject:[NSString stringWithFormat:@"location contains[c] '%@'", location]];
[predicateStrings addObject:@"location contains[c] %@"];
[predicateArguments addObject:location];
}
if (notes != (id)[NSNull null] && notes.length > 0) {
notes = [notes stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];
[predicateStrings addObject:[NSString stringWithFormat:@"notes contains[c] '%@'", notes]];
[predicateStrings addObject:@"notes contains[c] %@"];
[predicateArguments addObject:notes];
}

NSString *predicateString = [predicateStrings componentsJoinedByString:@" AND "];
Expand All @@ -322,7 +324,7 @@ - (NSArray*) findEKEventsWithTitle: (NSString *)title
NSArray *datedEvents, *matchingEvents;

if (predicateString.length > 0) {
matches = [NSPredicate predicateWithFormat:predicateString];
matches = [NSPredicate predicateWithFormat:predicateString argumentArray:predicateArguments];

datedEvents = [self.eventStore eventsMatchingPredicate:[eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendars]];

Expand Down

0 comments on commit 6149d3f

Please sign in to comment.