From 47a51c3d420bd5e22fc91e5faf02176884d05791 Mon Sep 17 00:00:00 2001 From: Lukas Mollidor Date: Fri, 8 Jan 2016 17:56:46 +0100 Subject: [PATCH] Fix NSRangeException by checking range of NSTextCheckingResult --- GCDWebServer/Core/GCDWebServer.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/GCDWebServer/Core/GCDWebServer.m b/GCDWebServer/Core/GCDWebServer.m index 7a1d0d1..815fab3 100644 --- a/GCDWebServer/Core/GCDWebServer.m +++ b/GCDWebServer/Core/GCDWebServer.m @@ -957,7 +957,12 @@ static inline NSString* _EncodeBase64(NSString* string) { for (NSTextCheckingResult* result in matches) { // Start at 1; index 0 is the whole string for (NSUInteger i = 1; i < result.numberOfRanges; i++) { - [captures addObject:[urlPath substringWithRange:[result rangeAtIndex:i]]]; + NSRange range = [result rangeAtIndex:i]; + // range is {NSNotFound, 0} "if one of the capture groups did not participate in this particular match" + // see discussion in -[NSRegularExpression firstMatchInString:options:range:] + if (range.location != NSNotFound) { + [captures addObject:[urlPath substringWithRange:range]]; + } } }