diff --git a/src/Runner.Worker/FileCommandManager.cs b/src/Runner.Worker/FileCommandManager.cs index b9470fba8..b47e2a37b 100644 --- a/src/Runner.Worker/FileCommandManager.cs +++ b/src/Runner.Worker/FileCommandManager.cs @@ -181,6 +181,10 @@ namespace GitHub.Runner.Worker { throw new Exception($"Invalid environment variable value. Matching delimiter not found '{delimiter}'"); } + if (newline == null) + { + throw new Exception($"Invalid environment variable value. EOF marker missing new line."); + } endIndex = index - newline.Length; tempLine = ReadLine(text, ref index, out newline); } diff --git a/src/Test/L0/Worker/SetEnvFileCommandL0.cs b/src/Test/L0/Worker/SetEnvFileCommandL0.cs index c655fb676..41f8499d5 100644 --- a/src/Test/L0/Worker/SetEnvFileCommandL0.cs +++ b/src/Test/L0/Worker/SetEnvFileCommandL0.cs @@ -302,6 +302,50 @@ namespace GitHub.Runner.Common.Tests.Worker } } + [Fact] + [Trait("Level", "L0")] + [Trait("Category", "Worker")] + public void SetEnvFileCommand_Heredoc_MissingNewLine() + { + using (var hostContext = Setup()) + { + var envFile = Path.Combine(_rootDirectory, "heredoc"); + var content = new List + { + "MY_ENV<(() => _setEnvFileCommand.ProcessCommand(_executionContext.Object, envFile, null)); + Assert.Contains("Matching delimiter not found", ex.Message); + } + } + + [Fact] + [Trait("Level", "L0")] + [Trait("Category", "Worker")] + public void SetEnvFileCommand_Heredoc_MissingNewLineMultipleLinesEnv() + { + using (var hostContext = Setup()) + { + var envFile = Path.Combine(_rootDirectory, "heredoc"); + var content = new List + { + "MY_ENV<(() => _setEnvFileCommand.ProcessCommand(_executionContext.Object, envFile, null)); + Assert.Contains("EOF marker missing new line", ex.Message); + } + } + #if OS_WINDOWS [Fact] [Trait("Level", "L0")]