From e38705a2f254807d7d78b1c944b834e535cb2b73 Mon Sep 17 00:00:00 2001 From: Yuriy Musiychuk Date: Tue, 21 Feb 2017 19:29:40 +0200 Subject: [PATCH] fix(ReactPage): Fix ApplyArguments to not fail on odd number of arguments (#1025) --- 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 815da65b2fb..72db3e0c34c 100644 --- a/ReactWindows/ReactNative.Net46/ReactPage.cs +++ b/ReactWindows/ReactNative.Net46/ReactPage.cs @@ -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; } diff --git a/ReactWindows/ReactNative/ReactPage.cs b/ReactWindows/ReactNative/ReactPage.cs index 86010a47984..76219539a92 100644 --- a/ReactWindows/ReactNative/ReactPage.cs +++ b/ReactWindows/ReactNative/ReactPage.cs @@ -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; }