From d6736ba61002f3617592d6d1468c803f74e6e83b Mon Sep 17 00:00:00 2001 From: ymusiychuk-lohika Date: Fri, 24 Feb 2017 02:31:10 +0200 Subject: [PATCH] fix(ReactPage): Fix ApplyArguments to not fail on odd number of arguments (#1025) (#1028) --- ReactWindows/ReactNative.Net46/ReactPage.cs | 15 ++++++++++----- ReactWindows/ReactNative/ReactPage.cs | 16 +++++++++++----- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/ReactWindows/ReactNative.Net46/ReactPage.cs b/ReactWindows/ReactNative.Net46/ReactPage.cs index d8a42d148c1..61a78b56343 100644 --- a/ReactWindows/ReactNative.Net46/ReactPage.cs +++ b/ReactWindows/ReactNative.Net46/ReactPage.cs @@ -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; } diff --git a/ReactWindows/ReactNative/ReactPage.cs b/ReactWindows/ReactNative/ReactPage.cs index 57e8cd8fadf..00b9ba45ef0 100644 --- a/ReactWindows/ReactNative/ReactPage.cs +++ b/ReactWindows/ReactNative/ReactPage.cs @@ -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; }