diff --git a/.autover/changes/fd1edd27-5324-4679-b0af-e2530bcc918f.json b/.autover/changes/fd1edd27-5324-4679-b0af-e2530bcc918f.json new file mode 100644 index 0000000..9b75592 --- /dev/null +++ b/.autover/changes/fd1edd27-5324-4679-b0af-e2530bcc918f.json @@ -0,0 +1,11 @@ +{ + "Projects": [ + { + "Name": "Amazon.Lambda.Tools", + "Type": "Patch", + "ChangelogMessages": [ + "Added logic to handle extraneous double-quotes around value for --msbuild-parameters that could be passed in .NET argument for certain execution environments." + ] + } + ] +} \ No newline at end of file diff --git a/src/Amazon.Common.DotNetCli.Tools/Options/CommandLineParser.cs b/src/Amazon.Common.DotNetCli.Tools/Options/CommandLineParser.cs index 97ce1dd..ea1735e 100644 --- a/src/Amazon.Common.DotNetCli.Tools/Options/CommandLineParser.cs +++ b/src/Amazon.Common.DotNetCli.Tools/Options/CommandLineParser.cs @@ -60,6 +60,14 @@ public static CommandOptions ParseArguments( value.BoolValue = bv; break; } + + // --msbuild-parameters is a special case where multiple parameters separated by space character are enclosed in double quotes. In certain environments (like JavaScript action runner), the leading and trailing double quotes characters are also passed to .NET command arguments. + if (option == CommonDefinedCommandOptions.ARGUMENT_MSBUILD_PARAMETERS && !string.IsNullOrEmpty(value.StringValue) + && (value.StringValue.Trim().StartsWith('\"') && value.StringValue.Trim().EndsWith('\"'))) + { + value.StringValue = value.StringValue.Trim().Trim('\"'); + } + i++; } diff --git a/test/Amazon.Lambda.Tools.Test/CommandLineParserTest.cs b/test/Amazon.Lambda.Tools.Test/CommandLineParserTest.cs index c94f770..2503700 100644 --- a/test/Amazon.Lambda.Tools.Test/CommandLineParserTest.cs +++ b/test/Amazon.Lambda.Tools.Test/CommandLineParserTest.cs @@ -93,5 +93,18 @@ public void BuildLambdaDeployCommandWithAllArguments() Assert.Equal(55, command.Timeout); Assert.Equal("netcore9.9", command.Runtime); } + + [Fact] + public void BuildLambdaDeployCommandWithMSBuildParamAndSwitchDoubleQuotedValue() + { + var arguments = new List(); + arguments.AddRange(new string[] { "--region", "us-west-2" }); + arguments.AddRange(new string[] { "--msbuild-parameters", "\"--no-restore --no-build\"" }); + arguments.Add("/p:Foo=bar;Version=1.2.3"); + + var command = new DeployFunctionCommand(new ConsoleToolLogger(), ".", arguments.ToArray()); + Assert.Equal("us-west-2", command.Region); + Assert.Equal("--no-restore --no-build /p:Foo=bar;Version=1.2.3", command.MSBuildParameters); + } } } diff --git a/test/Amazon.Lambda.Tools.Test/OptionParseTests.cs b/test/Amazon.Lambda.Tools.Test/OptionParseTests.cs index 0a49695..185606c 100644 --- a/test/Amazon.Lambda.Tools.Test/OptionParseTests.cs +++ b/test/Amazon.Lambda.Tools.Test/OptionParseTests.cs @@ -81,5 +81,39 @@ public void ParseMSBuildParameters() Assert.NotNull(param); Assert.Equal("us-west-2", param.Item2.StringValue); } + + [Fact] + public void ParseMSBuildSwitchDoubleQuotedValue() + { + var values = CommandLineParser.ParseArguments(DeployFunctionCommand.DeployCommandOptions, + new[] { "myfunc", "--region", "us-west-2", "--msbuild-parameters", "\"--no-restore --no-build\"" }); + + Assert.Equal("myfunc", values.Arguments[0]); + + var msbuildparametersParam = values.FindCommandOption("--msbuild-parameters"); + Assert.NotNull(msbuildparametersParam); + Assert.Equal("--no-restore --no-build", msbuildparametersParam.Item2.StringValue); + + var param = values.FindCommandOption("--region"); + Assert.NotNull(param); + Assert.Equal("us-west-2", param.Item2.StringValue); + } + + [Fact] + public void ParseMSBuildSwitchNotDoubleQuotedValue() + { + var values = CommandLineParser.ParseArguments(DeployFunctionCommand.DeployCommandOptions, + new[] { "myfunc", "--region", "us-west-2", "--msbuild-parameters", "--no-restore --no-build" }); + + Assert.Equal("myfunc", values.Arguments[0]); + + var msbuildparametersParam = values.FindCommandOption("--msbuild-parameters"); + Assert.NotNull(msbuildparametersParam); + Assert.Equal("--no-restore --no-build", msbuildparametersParam.Item2.StringValue); + + var param = values.FindCommandOption("--region"); + Assert.NotNull(param); + Assert.Equal("us-west-2", param.Item2.StringValue); + } } }