Fix usage of deprecated method stringByAddingPercentEscapesUsingEncoding:.
The method -[NSString stringByAddingPercentEscapesUsingEncoding:] has been deprecated with 10.11 OS X SDK and 9.0 iOS SDK. The recommended method is -[NSString stringByAddingPercentEncodingWithAllowedCharacters:] available since 10.9 OS X SDK and 7.0 iOS SDK. Use the new method when available using URLQueryAllowedCharacterSet to get the same encoded string. BUG=https://bugs.chromium.org/p/google-breakpad/issues/detail?id=675 BUG=569158 R=mark@chromium.org Review URL: https://codereview.chromium.org/1680663002 .
This commit is contained in:
parent
f4012f5cd9
commit
c4c887c34a
@ -30,6 +30,23 @@
|
||||
#import "HTTPMultipartUpload.h"
|
||||
#import "GTMDefines.h"
|
||||
|
||||
// As -[NSString stringByAddingPercentEscapesUsingEncoding:] has been
|
||||
// deprecated with iOS 9.0 / OS X 10.11 SDKs, this function re-implements it
|
||||
// using -[NSString stringByAddingPercentEncodingWithAllowedCharacters:] when
|
||||
// using those SDKs.
|
||||
static NSString *PercentEncodeNSString(NSString *key) {
|
||||
#if (defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && defined(__IPHONE_9_0) && \
|
||||
__IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_9_0) || \
|
||||
(defined(MAC_OS_X_VERSION_MIN_REQUIRED) && \
|
||||
defined(MAC_OS_X_VERSION_10_11) && \
|
||||
MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_11)
|
||||
return [key stringByAddingPercentEncodingWithAllowedCharacters:
|
||||
[NSCharacterSet URLQueryAllowedCharacterSet]];
|
||||
#else
|
||||
return [key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
#endif
|
||||
}
|
||||
|
||||
@interface HTTPMultipartUpload(PrivateMethods)
|
||||
- (NSString *)multipartBoundary;
|
||||
// Each of the following methods will append the starting multipart boundary,
|
||||
@ -52,8 +69,7 @@
|
||||
|
||||
//=============================================================================
|
||||
- (NSData *)formDataForKey:(NSString *)key value:(NSString *)value {
|
||||
NSString *escaped =
|
||||
[key stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
NSString *escaped = PercentEncodeNSString(key);
|
||||
NSString *fmt =
|
||||
@"--%@\r\nContent-Disposition: form-data; name=\"%@\"\r\n\r\n%@\r\n";
|
||||
NSString *form = [NSString stringWithFormat:fmt, boundary_, escaped, value];
|
||||
@ -64,8 +80,7 @@
|
||||
//=============================================================================
|
||||
- (NSData *)formDataForFileContents:(NSData *)contents name:(NSString *)name {
|
||||
NSMutableData *data = [NSMutableData data];
|
||||
NSString *escaped =
|
||||
[name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
|
||||
NSString *escaped = PercentEncodeNSString(name);
|
||||
NSString *fmt = @"--%@\r\nContent-Disposition: form-data; name=\"%@\"; "
|
||||
"filename=\"minidump.dmp\"\r\nContent-Type: application/octet-stream\r\n\r\n";
|
||||
NSString *pre = [NSString stringWithFormat:fmt, boundary_, escaped];
|
||||
|
Loading…
Reference in New Issue
Block a user