Skip to content

Commit 61ca119

Browse files
pvinisfacebook-github-bot
authored andcommitted
Replace deprecated stringByReplacingPercentEscapesUsingEncoding: with stringByAddingPercentEncodingWithAllowedCharacters: (#19792)
Summary: Replace some NSString deprecated methods. motivation for these prs is less warnings reported on xcode everytime we compile a rn app. N/A [INTERNAL] [DEPRECATIONS] [NSString] - Replace NSString deprecation methods. Pull Request resolved: #19792 Differential Revision: D8515136 Pulled By: cpojer fbshipit-source-id: 4379ef4e229ef201685b87e54ac859ba3d30a833
1 parent 5be50d4 commit 61ca119

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

React/Base/RCTConvert.m

+8-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,14 @@ + (NSURL *)NSURL:(id)json
8989

9090
// Check if it has a scheme
9191
if ([path rangeOfString:@":"].location != NSNotFound) {
92-
path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
92+
NSMutableCharacterSet *urlAllowedCharacterSet = [NSMutableCharacterSet new];
93+
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLUserAllowedCharacterSet]];
94+
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLPasswordAllowedCharacterSet]];
95+
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLHostAllowedCharacterSet]];
96+
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLPathAllowedCharacterSet]];
97+
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLQueryAllowedCharacterSet]];
98+
[urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLFragmentAllowedCharacterSet]];
99+
path = [path stringByAddingPercentEncodingWithAllowedCharacters:urlAllowedCharacterSet];
93100
URL = [NSURL URLWithString:path];
94101
if (URL) {
95102
return URL;

React/DevSupport/RCTInspectorDevServerHelper.mm

+4-4
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
static NSURL *getInspectorDeviceUrl(NSURL *bundleURL)
3434
{
3535
NSNumber *inspectorProxyPort = @8082;
36-
NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
37-
NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
36+
NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
37+
NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
3838
return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/inspector/device?name=%@&app=%@",
3939
getServerHost(bundleURL, inspectorProxyPort),
4040
escapedDeviceName,
@@ -44,8 +44,8 @@
4444
static NSURL *getAttachDeviceUrl(NSURL *bundleURL, NSString *title)
4545
{
4646
NSNumber *metroBundlerPort = @8081;
47-
NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
48-
NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
47+
NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet];
48+
NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet];
4949
return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/attach-debugger-nuclide?title=%@&device=%@&app=%@",
5050
getServerHost(bundleURL, metroBundlerPort),
5151
title,

React/Views/RCTWebView.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ - (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLR
247247
if (isJSNavigation && [request.URL.host isEqualToString:kPostMessageHost]) {
248248
NSString *data = request.URL.query;
249249
data = [data stringByReplacingOccurrencesOfString:@"+" withString:@" "];
250-
data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
250+
data = [data stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet];
251251

252252
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
253253
[event addEntriesFromDictionary: @{

0 commit comments

Comments
 (0)