diff --git a/src/VirtualClient/VirtualClient.Main/CommandLineExtensions.cs b/src/VirtualClient/VirtualClient.Main/CommandLineExtensions.cs index e62ffe37aa..7ae9fa6910 100644 --- a/src/VirtualClient/VirtualClient.Main/CommandLineExtensions.cs +++ b/src/VirtualClient/VirtualClient.Main/CommandLineExtensions.cs @@ -95,11 +95,14 @@ public static void ThrowOnUsageError(this ParseResult parseResults) } // Scenario 3: - // There are no options on the command line that are not valid for the command. + // There are options on the command line that are not valid for the command. + // Use a full-string match (anchored regex) to avoid false positives from + // values bound to recognized options that contain double-dash prefixed + // substrings (e.g. --parameters="...DriverInstallationCommandArguments=--silent..."). IEnumerable arguments = parseResults.Tokens.Where(t => t.Type == TokenType.Argument); if (arguments?.Any() == true) { - Regex optionMatchExpression = new Regex("--[a-z]+", RegexOptions.IgnoreCase); + Regex optionMatchExpression = new Regex(@"^--[a-z][-a-z]*$", RegexOptions.IgnoreCase); foreach (Token argument in arguments) { if (optionMatchExpression.IsMatch(argument.Value?.Trim())) diff --git a/src/VirtualClient/VirtualClient.UnitTests/CommandLineOptionTests.cs b/src/VirtualClient/VirtualClient.UnitTests/CommandLineOptionTests.cs index 8fc264cf40..c525dc1844 100644 --- a/src/VirtualClient/VirtualClient.UnitTests/CommandLineOptionTests.cs +++ b/src/VirtualClient/VirtualClient.UnitTests/CommandLineOptionTests.cs @@ -153,6 +153,7 @@ public void VirtualClientThrowsWhenAnUnrecognizedOptionIsSuppliedOnTheCommandLin [TestCase("--ps", "https://anystorageaccount.blob.core.windows.net/?sv=2020-08-04&ss=b")] [TestCase("--parameters", "Param1=Value1,,,Param2=Value2")] [TestCase("--pm", "Param1=Value1,,,Param2=Value2")] + [TestCase("--parameters", "DriverInstallationCommandArguments=--silent,,,UserName=HpcUser,,,DriverBlobName=nvidiagriddriver-v20.0.zip")] [TestCase("--seed", "1234")] [TestCase("--sd", "1234")] [TestCase("--scenarios", "Scenario1")]