소스 검색

Fix NSRangeException by checking range of NSTextCheckingResult

Lukas Mollidor 9 년 전
부모
커밋
47a51c3d42
1개의 변경된 파일6개의 추가작업 그리고 1개의 파일을 삭제
  1. 6 1
      GCDWebServer/Core/GCDWebServer.m

+ 6 - 1
GCDWebServer/Core/GCDWebServer.m

@@ -957,7 +957,12 @@ static inline NSString* _EncodeBase64(NSString* string) {
       for (NSTextCheckingResult* result in matches) {
       for (NSTextCheckingResult* result in matches) {
         // Start at 1; index 0 is the whole string
         // Start at 1; index 0 is the whole string
         for (NSUInteger i = 1; i < result.numberOfRanges; i++) {
         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]];
+          }
         }
         }
       }
       }