Skip to content

Commit 3f6b4be

Browse files
authoredFeb 24, 2022
Issue 1596: Runner throws null ref exception when new line after EOF is missing (#1687)
* Issue 1596: runner throws nullref exception when writting env var * Adding tests for missing new line after EOF marker * Changing newline to new line
1 parent b393801 commit 3f6b4be

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
 

‎src/Runner.Worker/FileCommandManager.cs

+4
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ public void ProcessCommand(IExecutionContext context, string filePath, Container
181181
{
182182
throw new Exception($"Invalid environment variable value. Matching delimiter not found '{delimiter}'");
183183
}
184+
if (newline == null)
185+
{
186+
throw new Exception($"Invalid environment variable value. EOF marker missing new line.");
187+
}
184188
endIndex = index - newline.Length;
185189
tempLine = ReadLine(text, ref index, out newline);
186190
}

‎src/Test/L0/Worker/SetEnvFileCommandL0.cs

+44
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,50 @@ public void SetEnvFileCommand_Heredoc_SpecialCharacters()
302302
}
303303
}
304304

305+
[Fact]
306+
[Trait("Level", "L0")]
307+
[Trait("Category", "Worker")]
308+
public void SetEnvFileCommand_Heredoc_MissingNewLine()
309+
{
310+
using (var hostContext = Setup())
311+
{
312+
var envFile = Path.Combine(_rootDirectory, "heredoc");
313+
var content = new List<string>
314+
{
315+
"MY_ENV<<EOF",
316+
"line one",
317+
"line two",
318+
"line three",
319+
"EOF",
320+
};
321+
WriteContent(envFile, content, " ");
322+
var ex = Assert.Throws<Exception>(() => _setEnvFileCommand.ProcessCommand(_executionContext.Object, envFile, null));
323+
Assert.Contains("Matching delimiter not found", ex.Message);
324+
}
325+
}
326+
327+
[Fact]
328+
[Trait("Level", "L0")]
329+
[Trait("Category", "Worker")]
330+
public void SetEnvFileCommand_Heredoc_MissingNewLineMultipleLinesEnv()
331+
{
332+
using (var hostContext = Setup())
333+
{
334+
var envFile = Path.Combine(_rootDirectory, "heredoc");
335+
var content = new List<string>
336+
{
337+
"MY_ENV<<EOF",
338+
@"line one
339+
line two
340+
line three",
341+
"EOF",
342+
};
343+
WriteContent(envFile, content, " ");
344+
var ex = Assert.Throws<Exception>(() => _setEnvFileCommand.ProcessCommand(_executionContext.Object, envFile, null));
345+
Assert.Contains("EOF marker missing new line", ex.Message);
346+
}
347+
}
348+
305349
#if OS_WINDOWS
306350
[Fact]
307351
[Trait("Level", "L0")]

0 commit comments

Comments
 (0)