Skip to content

Commit 3ce8925

Browse files
committed
Added logic to handle extraneous double-quotes around value for --msbuild-parameters that could be passed in .NET argument for certain execution environments.
1 parent fa1385e commit 3ce8925

File tree

4 files changed

+66
-0
lines changed

4 files changed

+66
-0
lines changed
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"Projects": [
3+
{
4+
"Name": "Amazon.Lambda.Tools",
5+
"Type": "Patch",
6+
"ChangelogMessages": [
7+
"Added logic to handle extraneous double-quotes around value for --msbuild-parameters that could be passed in .NET argument for certain execution environments."
8+
]
9+
}
10+
]
11+
}

src/Amazon.Common.DotNetCli.Tools/Options/CommandLineParser.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ public static CommandOptions ParseArguments(
6060
value.BoolValue = bv;
6161
break;
6262
}
63+
64+
// --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.
65+
if (option == CommonDefinedCommandOptions.ARGUMENT_MSBUILD_PARAMETERS && !string.IsNullOrEmpty(value.StringValue)
66+
&& (value.StringValue.Trim().StartsWith('\"') && value.StringValue.Trim().EndsWith('\"')))
67+
{
68+
value.StringValue = value.StringValue.Trim().Trim('\"');
69+
}
70+
6371
i++;
6472
}
6573

test/Amazon.Lambda.Tools.Test/CommandLineParserTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,18 @@ public void BuildLambdaDeployCommandWithAllArguments()
9393
Assert.Equal(55, command.Timeout);
9494
Assert.Equal("netcore9.9", command.Runtime);
9595
}
96+
97+
[Fact]
98+
public void BuildLambdaDeployCommandWithMSBuildParamAndSwitchDoubleQuotedValue()
99+
{
100+
var arguments = new List<string>();
101+
arguments.AddRange(new string[] { "--region", "us-west-2" });
102+
arguments.AddRange(new string[] { "--msbuild-parameters", "\"--no-restore --no-build\"" });
103+
arguments.Add("/p:Foo=bar;Version=1.2.3");
104+
105+
var command = new DeployFunctionCommand(new ConsoleToolLogger(), ".", arguments.ToArray());
106+
Assert.Equal("us-west-2", command.Region);
107+
Assert.Equal("--no-restore --no-build /p:Foo=bar;Version=1.2.3", command.MSBuildParameters);
108+
}
96109
}
97110
}

test/Amazon.Lambda.Tools.Test/OptionParseTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,5 +81,39 @@ public void ParseMSBuildParameters()
8181
Assert.NotNull(param);
8282
Assert.Equal("us-west-2", param.Item2.StringValue);
8383
}
84+
85+
[Fact]
86+
public void ParseMSBuildSwitchDoubleQuotedValue()
87+
{
88+
var values = CommandLineParser.ParseArguments(DeployFunctionCommand.DeployCommandOptions,
89+
new[] { "myfunc", "--region", "us-west-2", "--msbuild-parameters", "\"--no-restore --no-build\"" });
90+
91+
Assert.Equal("myfunc", values.Arguments[0]);
92+
93+
var msbuildparametersParam = values.FindCommandOption("--msbuild-parameters");
94+
Assert.NotNull(msbuildparametersParam);
95+
Assert.Equal("--no-restore --no-build", msbuildparametersParam.Item2.StringValue);
96+
97+
var param = values.FindCommandOption("--region");
98+
Assert.NotNull(param);
99+
Assert.Equal("us-west-2", param.Item2.StringValue);
100+
}
101+
102+
[Fact]
103+
public void ParseMSBuildSwitchNotDoubleQuotedValue()
104+
{
105+
var values = CommandLineParser.ParseArguments(DeployFunctionCommand.DeployCommandOptions,
106+
new[] { "myfunc", "--region", "us-west-2", "--msbuild-parameters", "--no-restore --no-build" });
107+
108+
Assert.Equal("myfunc", values.Arguments[0]);
109+
110+
var msbuildparametersParam = values.FindCommandOption("--msbuild-parameters");
111+
Assert.NotNull(msbuildparametersParam);
112+
Assert.Equal("--no-restore --no-build", msbuildparametersParam.Item2.StringValue);
113+
114+
var param = values.FindCommandOption("--region");
115+
Assert.NotNull(param);
116+
Assert.Equal("us-west-2", param.Item2.StringValue);
117+
}
84118
}
85119
}

0 commit comments

Comments
 (0)