Skip to content

Commit

Permalink
fix RCTNetworking contentType issue (#35640)
Browse files Browse the repository at this point in the history
Summary:
https://github.com/facebook/react-native/blob/96027f787ade1a465569975059426d2c03ee5ad0/Libraries/Network/RCTNetworking.mm#L418

because  `RCTNullIfNil(response.MIMEType)`,  `contentType` may be `[NSNull null]`

https://github.com/facebook/react-native/blob/96027f787ade1a465569975059426d2c03ee5ad0/Libraries/Network/RCTNetworking.mm#L114

Here only check `partContentType` is not nil, This causes the custom type never used

https://github.com/facebook/react-native/blob/96027f787ade1a465569975059426d2c03ee5ad0/Libraries/Network/RCTNetworking.mm#L334

more serious here, if `dataContentType` is `[NSNull null]` ,  it will crash the application

`-[NSNull hasPrefix:]: unrecognized selector sent to instance 0x7fff8004b700`

## Changelog

[iOS] [Fixed] - fix dataContentType may be [NSNull null] issue

Pull Request resolved: #35640

Reviewed By: cipolleschi

Differential Revision: D42067206

Pulled By: dmytrorykun

fbshipit-source-id: 073e6589111f5117486b69b8206a07ef1995c5b8
  • Loading branch information
malacca authored and facebook-github-bot committed Dec 15, 2022
1 parent 3487640 commit c0834b8
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Libraries/Network/RCTNetworking.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ - (RCTURLRequestCancellationBlock)handleResult:(NSDictionary<NSString *, id> *)r
// Print headers.
NSMutableDictionary<NSString *, NSString *> *headers = [_parts[0][@"headers"] mutableCopy];
NSString *partContentType = result[@"contentType"];
if (partContentType != nil) {
if (partContentType != nil && ![partContentType isEqual:[NSNull null]]) {
headers[@"content-type"] = partContentType;
}
[headers enumerateKeysAndObjectsUsingBlock:^(NSString *parameterKey, NSString *parameterValue, BOOL *stop) {
Expand Down Expand Up @@ -331,7 +331,8 @@ - (RCTURLRequestCancellationBlock)buildRequest:(NSDictionary<NSString *, id> *)q
request.HTTPBody = result[@"body"];
NSString *dataContentType = result[@"contentType"];
NSString *requestContentType = [request valueForHTTPHeaderField:@"Content-Type"];
BOOL isMultipart = [dataContentType hasPrefix:@"multipart"];
BOOL isMultipart = ![dataContentType isEqual:[NSNull null]] &&
[dataContentType hasPrefix:@"multipart"];

// For multipart requests we need to override caller-specified content type with one
// from the data object, because it contains the boundary string
Expand Down

0 comments on commit c0834b8

Please sign in to comment.