Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ReactPage): Fix ApplyArguments to not fail on odd number of args (#1025) #1028

Merged
merged 2 commits into from Feb 24, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions ReactWindows/ReactNative.Net46/ReactPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -212,14 +212,19 @@ private void ApplyArguments(string[] arguments)
return;
}

if (arguments.Length % 2 != 0)
var index = Array.IndexOf(arguments, "remoteDebugging");
if (index < 0)
{
throw new ArgumentException("Expected even number of arguments.", nameof(arguments));
return;
}

var index = Array.IndexOf(arguments, "remoteDebugging");
var isRemoteDebuggingEnabled = default(bool);
if (index % 2 == 0 && bool.TryParse(arguments[index + 1], out isRemoteDebuggingEnabled))
if (arguments.Length <= index + 1)
{
throw new ArgumentException("Expected value for remoteDebugging argument.", nameof(arguments));
}

bool isRemoteDebuggingEnabled;
if (bool.TryParse(arguments[index + 1], out isRemoteDebuggingEnabled))
{
ReactInstanceManager.DevSupportManager.IsRemoteDebuggingEnabled = isRemoteDebuggingEnabled;
}
Expand Down
16 changes: 11 additions & 5 deletions ReactWindows/ReactNative/ReactPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,20 @@ private void ApplyArguments(string arguments)
if (!string.IsNullOrEmpty(arguments))
{
var args = arguments.Split(',');
if (args.Length % 2 != 0)

var index = Array.IndexOf(args, "remoteDebugging");
if (index < 0)
{
throw new ArgumentException("Expected even number of arguments.", nameof(arguments));
return;
}

var index = Array.IndexOf(args, "remoteDebugging");
var isRemoteDebuggingEnabled = default(bool);
if (index % 2 == 0 && bool.TryParse(args[index + 1], out isRemoteDebuggingEnabled))
if (args.Length <= index + 1)
{
throw new ArgumentException("Expected value for remoteDebugging argument.", nameof(arguments));
}

bool isRemoteDebuggingEnabled;
if (bool.TryParse(args[index + 1], out isRemoteDebuggingEnabled))
{
_reactInstanceManager.DevSupportManager.IsRemoteDebuggingEnabled = isRemoteDebuggingEnabled;
}
Expand Down