diff --git a/ChangeLog b/ChangeLog index 6065d08b5..751fbfd32 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2015-09-01 Niels Grewe + + * Source/NSRegularExpression.m: Fix handling of empty capture groups. + 2015-08-30 Richard Frith-Macdonald * Source/NSOperation.m: Fix potential deadlock with adding observers. diff --git a/Source/NSRegularExpression.m b/Source/NSRegularExpression.m index df0cd12b3..3c4de5183 100644 --- a/Source/NSRegularExpression.m +++ b/Source/NSRegularExpression.m @@ -297,8 +297,18 @@ prepareResult(NSRegularExpression *regex, for (i = 0; i < groups; i++) { - NSUInteger start = uregex_start(r, i, s); - NSUInteger end = uregex_end(r, i, s); + NSInteger start = uregex_start(r, i, s); + NSInteger end = uregex_end(r, i, s); + // The ICU API defines -1 as not found. Convert to + // NSNotFound if applicable. + if (start == -1) + { + start = NSNotFound; + } + if (end == -1) + { + end = NSNotFound; + } if (end < start) {