Skip to content

Commit 2b35261

Browse files
committed
fix(tooling): skip null and empty arguments
1 parent 9792725 commit 2b35261

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

source/Nuke.Common.Tests/SettingsTest.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ public void TestDotNet()
122122
"run --property:foo=bar --property:InformationalVersion=version -- arg1 arg2");
123123
}
124124

125+
[Fact]
126+
public void TestDotNet_Empty()
127+
{
128+
Assert(new DotNetBuildSettings()
129+
.SetFramework(null)
130+
.SetConfiguration("")
131+
.SetProperty("foo1", null)
132+
.SetProperty("foo2", ""),
133+
"build");
134+
}
135+
125136
[Fact]
126137
public void TestDocker()
127138
{

source/Nuke.Tooling/ToolOptions.Arguments.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,9 @@ IEnumerable<string> GetScalarArguments()
136136
yield break;
137137

138138
var value = Parse(token, property.PropertyType);
139+
if (value.IsNullOrWhiteSpace())
140+
yield break;
141+
139142
foreach (var part in formatParts)
140143
yield return part.Replace(ValuePlaceholder, value);
141144
}
@@ -145,7 +148,7 @@ IEnumerable<string> GetListArguments()
145148
Assert.True(formatParts.Length <= 2);
146149

147150
var valueType = property.PropertyType.GetScalarType();
148-
var values = token.Value<JArray>().Select(x => Parse(x, valueType));
151+
var values = token.Value<JArray>().Select(x => Parse(x, valueType)).Where(x => !x.IsNullOrWhiteSpace());
149152

150153
if (attribute.Separator == null)
151154
{
@@ -175,7 +178,8 @@ from part in formatParts
175178
IEnumerable<string> GetDictionaryArguments()
176179
{
177180
var valueType = property.PropertyType.GetGenericArguments().Last();
178-
var pairs = token.Value<JObject>().Properties().Select(x => (Key: x.Name, Value: Parse(x, valueType)));
181+
var pairs = token.Value<JObject>().Properties().Select(x => (Key: x.Name, Value: Parse(x, valueType)))
182+
.Where(x => !x.Value.IsNullOrWhiteSpace());
179183

180184
if (attribute.Separator == null)
181185
{
@@ -205,7 +209,7 @@ IEnumerable<string> GetLookupArguments()
205209
{
206210
var valueType = property.PropertyType.GetGenericArguments().Last();
207211
var pairs = token.Value<JObject>().Properties()
208-
.Select(x => (Key: x.Name, Values: x.Value.Value<JArray>().Select(x => Parse(x, valueType))));
212+
.Select(x => (Key: x.Name, Values: x.Value.Value<JArray>().Select(x => Parse(x, valueType)).Where(x => !x.IsNullOrWhiteSpace())));
209213

210214
if (attribute.Separator == null)
211215
{

0 commit comments

Comments
 (0)