Dear Maintainer,
-[NSRegularExpression stringByReplacingMatchesInString:options:range:withTemplate:]
returns nil instead of @"" whenever the result of the replacement is
empty, e.g. when the pattern matches the whole input, or the input is
empty. -replaceMatchesInString:options:range:withTemplate: has the same
problem and leaves the mutable string untouched.
Debian builds the non-UText code path, which first asks ICU for the output
length with a zero-sized buffer:
outLength = uregex_replaceAll(r, replacement, replLength, NULL, 0, &s);
if (0 == s || U_BUFFER_OVERFLOW_ERROR == s)
For an empty result ICU returns 0 with U_STRING_NOT_TERMINATED_WARNING,
which is a warning (negative), not an error, but the "0 == s" check
treats it as a failure and the method returns nil.
Upstream fixed this in libs-base commit 188b2a3faee4 ("fix for issue
#800"), which replaces the "0 == s" checks with U_SUCCESS(s) throughout
Source/NSRegularExpression.m and adds test cases:
https://github.com/gnustep/libs-base/commit/188b2a3faee4e88d3371000690d0930e15545f06
The replacement hunks apply to 1.31.1 with small offsets. The two
uregex_lookingAt()/uregex_findNext() hunks need adjusting by hand, as
upstream refactored that code in 09de0f4720fa. Please consider
backporting it.
Thanks,
Jordi