From 61119c10633fd396abd9dd7348bf5653ac2d3351 Mon Sep 17 00:00:00 2001 From: Pavlos Vinieratos Date: Tue, 5 Jun 2018 14:51:53 +0200 Subject: [PATCH 1/4] replace deprecated `stringByReplacingPercentEscapesUsingEncoding:` with `stringByAddingPercentEncodingWithAllowedCharacters:` --- React/Base/RCTConvert.m | 2 +- React/DevSupport/RCTInspectorDevServerHelper.mm | 8 ++++---- React/Views/RCTWebView.m | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 7bae9fbc5b31ef..35a396aeef961a 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -89,7 +89,7 @@ + (NSURL *)NSURL:(id)json // Check if it has a scheme if ([path rangeOfString:@":"].location != NSNotFound) { - path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + path = [path stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; URL = [NSURL URLWithString:path]; if (URL) { return URL; diff --git a/React/DevSupport/RCTInspectorDevServerHelper.mm b/React/DevSupport/RCTInspectorDevServerHelper.mm index 2901b68335c610..9f2ae6e4cdb130 100644 --- a/React/DevSupport/RCTInspectorDevServerHelper.mm +++ b/React/DevSupport/RCTInspectorDevServerHelper.mm @@ -33,8 +33,8 @@ static NSURL *getInspectorDeviceUrl(NSURL *bundleURL) { NSNumber *inspectorProxyPort = @8082; - NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; + NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/inspector/device?name=%@&app=%@", getServerHost(bundleURL, inspectorProxyPort), escapedDeviceName, @@ -44,8 +44,8 @@ static NSURL *getAttachDeviceUrl(NSURL *bundleURL, NSString *title) { NSNumber *metroBundlerPort = @8081; - NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; + NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/attach-debugger-nuclide?title=%@&device=%@&app=%@", getServerHost(bundleURL, metroBundlerPort), title, diff --git a/React/Views/RCTWebView.m b/React/Views/RCTWebView.m index a634efc3daf9a1..16af453eeb9a6e 100644 --- a/React/Views/RCTWebView.m +++ b/React/Views/RCTWebView.m @@ -247,7 +247,7 @@ - (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLR if (isJSNavigation && [request.URL.host isEqualToString:kPostMessageHost]) { NSString *data = request.URL.query; data = [data stringByReplacingOccurrencesOfString:@"+" withString:@" "]; - data = [data stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + data = [data stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary: @{ From e4736b23558ab0825871efcfcb30379218887b8a Mon Sep 17 00:00:00 2001 From: Pavlos Vinieratos Date: Fri, 25 Jan 2019 12:03:21 +0100 Subject: [PATCH 2/4] this is a query string, so use query --- React/Views/RCTWebView.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/React/Views/RCTWebView.m b/React/Views/RCTWebView.m index 16af453eeb9a6e..8f61e38041439e 100644 --- a/React/Views/RCTWebView.m +++ b/React/Views/RCTWebView.m @@ -247,7 +247,7 @@ - (BOOL)webView:(__unused UIWebView *)webView shouldStartLoadWithRequest:(NSURLR if (isJSNavigation && [request.URL.host isEqualToString:kPostMessageHost]) { NSString *data = request.URL.query; data = [data stringByReplacingOccurrencesOfString:@"+" withString:@" "]; - data = [data stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; + data = [data stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet]; NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary: @{ From 1183e32f36df1494a28dfd2f7542ede9d81332de Mon Sep 17 00:00:00 2001 From: Pavlos Vinieratos Date: Fri, 25 Jan 2019 12:04:31 +0100 Subject: [PATCH 3/4] these are used as queries so use query --- React/DevSupport/RCTInspectorDevServerHelper.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/React/DevSupport/RCTInspectorDevServerHelper.mm b/React/DevSupport/RCTInspectorDevServerHelper.mm index 9f2ae6e4cdb130..e157ef5da11fd2 100644 --- a/React/DevSupport/RCTInspectorDevServerHelper.mm +++ b/React/DevSupport/RCTInspectorDevServerHelper.mm @@ -33,8 +33,8 @@ static NSURL *getInspectorDeviceUrl(NSURL *bundleURL) { NSNumber *inspectorProxyPort = @8082; - NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; - NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; + NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet]; + NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet]; return [NSURL URLWithString:[NSString stringWithFormat:@"http://%@/inspector/device?name=%@&app=%@", getServerHost(bundleURL, inspectorProxyPort), escapedDeviceName, From 5cab75844568eb4f646603228dfab936ef547e19 Mon Sep 17 00:00:00 2001 From: Pavlos Vinieratos Date: Fri, 25 Jan 2019 12:21:33 +0100 Subject: [PATCH 4/4] this is encoding the whole url, so use all allowed url parts --- React/Base/RCTConvert.m | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 35a396aeef961a..fcb8ec167d1def 100644 --- a/React/Base/RCTConvert.m +++ b/React/Base/RCTConvert.m @@ -89,7 +89,14 @@ + (NSURL *)NSURL:(id)json // Check if it has a scheme if ([path rangeOfString:@":"].location != NSNotFound) { - path = [path stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLHostAllowedCharacterSet]; + NSMutableCharacterSet *urlAllowedCharacterSet = [NSMutableCharacterSet new]; + [urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLUserAllowedCharacterSet]]; + [urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLPasswordAllowedCharacterSet]]; + [urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLHostAllowedCharacterSet]]; + [urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLPathAllowedCharacterSet]]; + [urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLQueryAllowedCharacterSet]]; + [urlAllowedCharacterSet formUnionWithCharacterSet:[NSCharacterSet URLFragmentAllowedCharacterSet]]; + path = [path stringByAddingPercentEncodingWithAllowedCharacters:urlAllowedCharacterSet]; URL = [NSURL URLWithString:path]; if (URL) { return URL;