Skip to content

Commit

Permalink
fix(ReactPage): Fix ApplyArguments to not fail on odd number of argum…
Browse files Browse the repository at this point in the history
…ents (#1025) (#1028)
  • Loading branch information
ymusiychuk-lohika authored and rozele committed Mar 6, 2017
1 parent 828c5ae commit 9c7af25
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
15 changes: 10 additions & 5 deletions ReactWindows/ReactNative.Net46/ReactPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,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 @@ -203,14 +203,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

0 comments on commit 9c7af25

Please sign in to comment.