Skip to content

Commit

Permalink
Move URL escaping to Inspector layer
Browse files Browse the repository at this point in the history
Reviewed By: Hypuk

Differential Revision: D5967544

fbshipit-source-id: d741e6324aff7583778cb13c862505b61ca02a3d
  • Loading branch information
pakoito authored and facebook-github-bot committed Oct 4, 2017
1 parent eae4fe8 commit ef2e29f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
9 changes: 5 additions & 4 deletions React/CxxBridge/RCTCxxBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -328,13 +328,14 @@ - (void)start
BOOL useCustomJSC =
[self.delegate respondsToSelector:@selector(shouldBridgeUseCustomJSC:)] &&
[self.delegate shouldBridgeUseCustomJSC:self];
NSString *escapedDeviceName = [[[UIDevice currentDevice] name] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSString *escapedAppName = [[[NSBundle mainBundle] bundleIdentifier] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
// We use the name of the device and the app for debugging & metrics
NSString *deviceName = [[UIDevice currentDevice] name];
NSString *appName = [[NSBundle mainBundle] bundleIdentifier];
// The arg is a cache dir. It's not used with standard JSC.
executorFactory.reset(new JSCExecutorFactory(folly::dynamic::object
("OwnerIdentity", "ReactNative")
("AppIdentity", [(escapedAppName ?: @"unknown") UTF8String])
("DeviceIdentity", [(escapedDeviceName ?: @"unknown") UTF8String])
("AppIdentity", [(appName ?: @"unknown") UTF8String])
("DeviceIdentity", [(deviceName ?: @"unknown") UTF8String])
("UseCustomJSC", (bool)useCustomJSC)
#if RCT_PROFILE
("StartSamplingProfilerOnInit", (bool)self.devSettings.startSamplingProfilerOnLaunch)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import android.app.Activity;
import android.app.Application;
import android.net.Uri;
import android.os.Build;
import com.facebook.infer.annotation.Assertions;
import com.facebook.react.bridge.JSBundleLoader;
Expand Down Expand Up @@ -266,8 +265,9 @@ public ReactInstanceManager build() {
mUIImplementationProvider = new UIImplementationProvider();
}

String appName = Uri.encode(mApplication.getPackageName());
String deviceName = Uri.encode(getFriendlyDeviceName());
// We use the name of the device and the app for debugging & metrics
String appName = mApplication.getPackageName();
String deviceName = getFriendlyDeviceName();

return new ReactInstanceManager(
mApplication,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static String getInspectorProxyHost() {
return getServerIpAddress(INSPECTOR_PROXY_PORT);
}

// FIXME(festevezga): This method is duplicated in an internal module. Any changes should be applied to both.
// WARNING(festevezga): This RN helper method has been copied to another FB-only target. Any changes should be applied to both.
public static String getFriendlyDeviceName() {
if (isRunningOnGenymotion()) {
// Genymotion already has a friendly name by default
Expand Down
10 changes: 7 additions & 3 deletions ReactCommon/cxxreact/JSCExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <folly/Exception.h>
#include <folly/json.h>
#include <folly/Memory.h>
#include <folly/String.h>
#include <glog/logging.h>
#include <jschelpers/InspectorInterfaces.h>
#include <jschelpers/JSCHelpers.h>
Expand Down Expand Up @@ -295,10 +296,13 @@ namespace facebook {
#endif //defined(__ANDROID__)
}

std::string escapedOwner = folly::uriEscape<std::string>(owner, folly::UriEscapeMode::QUERY);
std::string escapedApp = folly::uriEscape<std::string>(app, folly::UriEscapeMode::QUERY);
std::string escapedDevice = folly::uriEscape<std::string>(device, folly::UriEscapeMode::QUERY);
std::string msg = folly::to<std::string>(
"GET /autoattach?title=", owner,
"&app=" , app,
"&device=" , device,
"GET /autoattach?title=", escapedOwner,
"&app=" , escapedApp,
"&device=" , escapedDevice,
" HTTP/1.1\r\n\r\n");
auto send_resp = ::send(socket_desc, msg.c_str(), msg.length(), 0);
if (send_resp < 0) {
Expand Down

0 comments on commit ef2e29f

Please sign in to comment.