[Debian GNUstep maintainers] Bug#1150228: libgnustep-base1.31: NSRegularExpression returns nil when a replacement yields an empty string

Jordi Mallach jordi at debian.org
Wed Oct 7 12:33:33 BST 2026


Package: libgnustep-base1.31
Version: 1.31.1-4+b2
Severity: important
Tags: patch fixed-upstream
Forwarded: https://github.com/gnustep/libs-base/issues/800
Control: affects -1 src:sogo

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



More information about the pkg-GNUstep-maintainers mailing list