Do not send null or empty values
MODIFY
src/WebJobs.Script/OutOfProc/Rpc/LanguageWorkerChannel.cs
src/WebJobs.Script/OutOfProc/Rpc/LanguageWorkerChannel.cs
@@ -224,9 +224,13 @@ internal FunctionEnvironmentReloadRequest GetFunctionEnvironmentReloadRequest(ID
{
FunctionEnvironmentReloadRequest request = new FunctionEnvironmentReloadRequest();
foreach (DictionaryEntry entry in processEnv)
+ {
+ // Do not add environment variables with empty or null values (see issue #4488 for context)
+ if (!string.IsNullOrEmpty(entry.Value?.ToString()))
{
request.EnvironmentVariables.Add(entry.Key.ToString(), entry.Value.ToString());
}
+ }
return request;
}

MODIFY
test/WebJobs.Script.Tests/Rpc/LanguageWorkerChannelTests.cs
test/WebJobs.Script.Tests/Rpc/LanguageWorkerChannelTests.cs
@@ -214,10 +214,14 @@ public async Task SendSendFunctionEnvironmentReloadRequest_ThrowsTimeout()
[Fact]
public void SendSendFunctionEnvironmentReloadRequest_SanitizedEnvironmentVariables()
{
- Environment.SetEnvironmentVariable("TestNull", null);
- Environment.SetEnvironmentVariable("TestEmpty", string.Empty);
- Environment.SetEnvironmentVariable("TestValid", "TestValue");
- FunctionEnvironmentReloadRequest envReloadRequest = _workerChannel.GetFunctionEnvironmentReloadRequest(Environment.GetEnvironmentVariables());
+ var environmentVariables = new Dictionary<string, string>()
+ {
+ { "TestNull", null },
+ { "TestEmpty", string.Empty },
+ { "TestValid", "TestValue" }
+ };
+
+ FunctionEnvironmentReloadRequest envReloadRequest = _workerChannel.GetFunctionEnvironmentReloadRequest(environmentVariables);
Assert.False(envReloadRequest.EnvironmentVariables.ContainsKey("TestNull"));
Assert.False(envReloadRequest.EnvironmentVariables.ContainsKey("TestEmpty"));
Assert.True(envReloadRequest.EnvironmentVariables.ContainsKey("TestValid"));

Do not send null or empty values (#5128)