Skip to content

Commit

Permalink
NSString: fix -commonPrefixWithString:options: behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
hmelder committed Oct 28, 2024
1 parent f133f1d commit 878e3a0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Source/NSString.m
Original file line number Diff line number Diff line change
Expand Up @@ -3227,6 +3227,11 @@ - (NSUInteger) hash
- (NSString*) commonPrefixWithString: (NSString*)aString
options: (NSUInteger)mask
{
// Return empty string to match behaviour on macOS
if (nil == aString)
{
return @"";
}
if (mask & NSLiteralSearch)
{
int prefix_len = 0;
Expand Down
3 changes: 3 additions & 0 deletions Tests/base/NSString/basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ int main()
PASS([@"" isEqual: nil] == NO, "an empty string is not null");
PASS([@"" isEqualToString: nil] == NO, "an empty string is not null");

s = [@"test" commonPrefixWithString: nil options: 0];
PASS_EQUAL(s, @"", "Common prefix of some string with nil is empty string");

[arp release]; arp = nil;
return 0;
}

0 comments on commit 878e3a0

Please sign in to comment.