From 93494d8f399b58d5f718318597d410d991f0031d Mon Sep 17 00:00:00 2001 From: Nuno Azevedo Date: Thu, 7 Nov 2019 17:09:37 +0000 Subject: [PATCH] fix: let NSPredicate handle predicate arguments The old code was crashing when using special characters such as quotes and newlines. This fix allows the actual NSPredicate class to handle the arguments. References https://outsystemsrd.atlassian.net/browse/RNMT-3533 --- src/ios/Calendar.m | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/ios/Calendar.m b/src/ios/Calendar.m index c6c22202..0e5525a9 100644 --- a/src/ios/Calendar.m +++ b/src/ios/Calendar.m @@ -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 "]; @@ -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]];