Skip to content

Commit 8c97df8

Browse files
Include also null entries as empty when building InvocationRequest payload for OOP workers (#8989)
* Include also null entries as empty when building InvocationRequest payload for OOP workers * Better comment on explaining the ?? string.Empty Co-authored-by: Wessel Kranenborg <[email protected]>
1 parent 83081e1 commit 8c97df8

File tree

2 files changed

+6
-11
lines changed

2 files changed

+6
-11
lines changed

src/WebJobs.Script.Grpc/MessageExtensions/GrpcMessageConversionExtensions.cs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -301,19 +301,14 @@ internal static TypedData ToRpcStringArray(this string[] arrString, bool include
301301
CollectionString collectionString = new CollectionString();
302302
foreach (string element in arrString)
303303
{
304-
// Don't add null entries.("Add" method below will throw)
305-
if (element is null)
304+
// Empty string/null entries are okay to add based on includeEmptyEntries param value.
305+
if (string.IsNullOrEmpty(element) && !includeEmptyEntries)
306306
{
307307
continue;
308308
}
309309

310-
// Empty string entries are okay to add based on includeEmptyEntries param value.
311-
if (element == string.Empty && !includeEmptyEntries)
312-
{
313-
continue;
314-
}
315-
316-
collectionString.String.Add(element);
310+
// Convert null entries to emptyEntry because "Add" method doesn't support null (will throw)
311+
collectionString.String.Add(element ?? string.Empty);
317312
}
318313
typedData.CollectionString = collectionString;
319314

test/WebJobs.Script.Tests/Workers/Rpc/GrpcMessageConversionExtensionsTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ public async Task ToRpc_Collection_String_IgnoreEmptyEntries_When_Capability_Is_
503503
}
504504

505505
[Fact]
506-
public async Task ToRpc_Collection_String_IncludeEmptyEntries_When_Capability_Is_Present()
506+
public async Task ToRpc_Collection_String_IncludeEmptyAndNullEntries_When_Capability_Is_Present()
507507
{
508508
var logger = MockNullLoggerFactory.CreateLogger();
509509
var capabilities = new GrpcCapabilities(logger);
@@ -516,7 +516,7 @@ public async Task ToRpc_Collection_String_IncludeEmptyEntries_When_Capability_Is
516516
string[] arrString = { "element1", string.Empty, "element_2", null };
517517
TypedData actual = await arrString.ToRpc(logger, capabilities);
518518

519-
var expected = new RepeatedField<string> { "element1", string.Empty, "element_2" }; // null entry should be still skipped
519+
var expected = new RepeatedField<string> { "element1", string.Empty, "element_2", string.Empty }; // null entry should be converted to string.Empty because collection doesn't support null's
520520
Assert.Equal(expected, actual.CollectionString.String);
521521
}
522522

0 commit comments

Comments
 (0)