Merge pull request #291 from qmfrederik/fixes/nsdata-base64-empty-string

`[NSData initWithBase64EncodedString]`: Fix decoding of an empty string
This commit is contained in:
rfm 2023-04-07 15:29:22 +01:00 committed by GitHub
commit 96a8613dbc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View file

@ -804,6 +804,13 @@ failure:
}
}
length = dst - result;
if (length == 0)
{
NSZoneFree(zone, result);
return [self initWithBytesNoCopy: 0 length: 0 freeWhenDone: YES];
}
if (options & NSDataBase64DecodingIgnoreUnknownCharacters)
{
/* If the decoded length is a lot shorter than expected (because we

View file

@ -127,6 +127,12 @@ int main()
PASS_EQUAL(data, ref, "base64 decoding Yml0bWFya2V0cyB1c2VyIGluZGVudGl0eQ==")
[data release];
data = [[NSData alloc] initWithBase64EncodedString: @"\n"
options: NSDataBase64DecodingIgnoreUnknownCharacters];
ref = [NSData dataWithBytes: "" length: 0];
PASS_EQUAL(data, ref, "base64 decoding empty string")
[data release];
[arp release]; arp = nil;
return 0;
}