Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added logic to handle extraneous double-quotes around value for --msbuild-parameters that could be passed in .NET argument for certain execution environments. #360

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .autover/changes/fd1edd27-5324-4679-b0af-e2530bcc918f.json
Original file line number Diff line number Diff line change
@@ -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."
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}

Expand Down
13 changes: 13 additions & 0 deletions test/Amazon.Lambda.Tools.Test/CommandLineParserTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>();
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);
}
}
}
34 changes: 34 additions & 0 deletions test/Amazon.Lambda.Tools.Test/OptionParseTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,39 @@ public void ParseMSBuildParameters()
Assert.NotNull(param);
Assert.Equal("us-west-2", param.Item2.StringValue);
}

[Fact]
public void ParseMSBuildSwitchDoubleQuotedValue()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you add a test case for when -msbuild-parameters does not have double quotes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added. I also added additional test in test/Amazon.Lambda.Tools.Test/CommandLineParserTest.cs that has scenario where both --msbuild-parameters enclosed in double quote and /p: MSBuild parameters are present.

{
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);
}
}
}
Loading