diff --git a/React/Base/RCTConvert.m b/React/Base/RCTConvert.m index 7bae9fbc5b31ef..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 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + 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; diff --git a/React/DevSupport/RCTInspectorDevServerHelper.mm b/React/DevSupport/RCTInspectorDevServerHelper.mm index 2901b68335c610..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] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + 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, @@ -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..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 stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; + data = [data stringByAddingPercentEncodingWithAllowedCharacters:NSCharacterSet.URLQueryAllowedCharacterSet]; NSMutableDictionary *event = [self baseEvent]; [event addEntriesFromDictionary: @{