From a79ff46c2d847db4ef6cc64d93acea8abd0bde1a Mon Sep 17 00:00:00 2001 From: thebeing Date: Tue, 1 Sep 2015 11:31:16 +0000 Subject: [PATCH] Fix handling of capture groups not participating in the current match. The Cocoa API specifies to return theses as (NSNotFound,0) ranges, but the ICU API returns them as (-1,-1) pairs of start/end indices. The necessary conversion was missing here. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@38963 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 4 ++++ Source/NSRegularExpression.m | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) 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) {