diff --git a/src/DockerfileModel/DockerfileModel.Tests/RunInstructionTests.cs b/src/DockerfileModel/DockerfileModel.Tests/RunInstructionTests.cs index 9f2efcb..063bc66 100644 --- a/src/DockerfileModel/DockerfileModel.Tests/RunInstructionTests.cs +++ b/src/DockerfileModel/DockerfileModel.Tests/RunInstructionTests.cs @@ -137,6 +137,20 @@ public static IEnumerable ParseTestInput() } }, new RunInstructionParseTestScenario + { + Text = "RUN `\n`\necho hello", + EscapeChar = '`', + TokenValidators = new Action[] + { + token => ValidateKeyword(token, "RUN"), + token => ValidateWhitespace(token, " "), + token => ValidateLineContinuation(token, '`', "\n"), + token => ValidateLineContinuation(token, '`', "\n"), + token => ValidateAggregate(token, "echo hello", + token => ValidateLiteral(token, "echo hello")) + } + }, + new RunInstructionParseTestScenario { Text = "RUN echo `\n#test comment\nhello", EscapeChar = '`', diff --git a/src/DockerfileModel/DockerfileModel.Tests/ShellFormCommandTests.cs b/src/DockerfileModel/DockerfileModel.Tests/ShellFormCommandTests.cs index f5ab3e2..ce3f2db 100644 --- a/src/DockerfileModel/DockerfileModel.Tests/ShellFormCommandTests.cs +++ b/src/DockerfileModel/DockerfileModel.Tests/ShellFormCommandTests.cs @@ -109,6 +109,20 @@ public static IEnumerable ParseTestInput() } }, new ShellFormCommandParseTestScenario + { + Text = "echo`\n `\n hello", + EscapeChar = '`', + TokenValidators = new Action[] + { + token => ValidateAggregate(token, "echo`\n `\n hello", + token => ValidateString(token, "echo"), + token => ValidateLineContinuation(token, '`', "\n"), + token => ValidateString(token, " "), + token => ValidateLineContinuation(token, '`', "\n"), + token => ValidateString(token, " hello")), + } + }, + new ShellFormCommandParseTestScenario { Text = "ec`\nho `test", EscapeChar = '`', diff --git a/src/DockerfileModel/DockerfileModel/ParseHelper.cs b/src/DockerfileModel/DockerfileModel/ParseHelper.cs index e22b928..07db6e2 100644 --- a/src/DockerfileModel/DockerfileModel/ParseHelper.cs +++ b/src/DockerfileModel/DockerfileModel/ParseHelper.cs @@ -308,9 +308,11 @@ public static Parser> LiteralString(char escapeChar, IEnumera /// /// Escape character. public static Parser> ArgumentListAsLiteral(char escapeChar) => - from literals in ArgTokens( - LiteralToken(escapeChar, Enumerable.Empty()).AsEnumerable(), - escapeChar).Many() + from literals in + ArgTokens( + from literal in LiteralToken(escapeChar, Enumerable.Empty()).Optional() + select new Token[] { literal.GetOrDefault() }, + escapeChar).Many() select CollapseLiteralTokens(literals.Flatten(), canContainVariables: false, escapeChar); ///