diff --git a/src/Runner.Worker/FileCommandManager.cs b/src/Runner.Worker/FileCommandManager.cs index 72ed5de0a..919f004ab 100644 --- a/src/Runner.Worker/FileCommandManager.cs +++ b/src/Runner.Worker/FileCommandManager.cs @@ -322,9 +322,21 @@ namespace GitHub.Runner.Worker var equalsIndex = line.IndexOf("=", StringComparison.Ordinal); var heredocIndex = line.IndexOf("<<", StringComparison.Ordinal); - // Heredoc style NAME<= 0 && (equalsIndex < 0 || heredocIndex < equalsIndex)) + // "key=<= 0 && + ( + equalsIndex < 0 || + ( + heredocIndex > equalsIndex && + OnlyContainsWhiteSpaceBetweenPositions(line, equalsIndex, heredocIndex) + ) || + heredocIndex < equalsIndex + ); + + if (isHeredoc) { var split = line.Split(new[] { "<<" }, 2, StringSplitOptions.None); if (string.IsNullOrEmpty(split[0]) || string.IsNullOrEmpty(split[1])) @@ -383,6 +395,34 @@ namespace GitHub.Runner.Worker return GetEnumerator(); } + // accepts a string, two indexes, and returns true if only whitespace chars exist between those two indexes (non-inclusive) + private static bool CheckIfOnlyWhitespaceBetweenSymbols(string str, int pos1, int pos2) + { + // Check if the provided positions are valid + if (pos1 < 0 || pos2 < 0 || pos1 >= str.Length || pos2 >= str.Length) + { + throw new ArgumentOutOfRangeException("Whitespace check: Positions should be within the string length."); + } + + // Ensure pos1 is always the smaller position + if (pos2 < pos1) + { + int temp = pos2; + pos2 = pos1; + pos1 = temp; + } + + for (int i = pos1 + 1; i < pos2; i++) + { + if (!char.IsWhiteSpace(str[i])) + { + return false; + } + } + + return true; + } + private static string ReadLine( string text, ref int index)