Skip to content

Commit

Permalink
Fix parsing of empty line continuations for commands (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthalman authored Nov 26, 2020
1 parent 67393f0 commit 35be2c4
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
14 changes: 14 additions & 0 deletions src/DockerfileModel/DockerfileModel.Tests/RunInstructionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,20 @@ public static IEnumerable<object[]> ParseTestInput()
}
},
new RunInstructionParseTestScenario
{
Text = "RUN `\n`\necho hello",
EscapeChar = '`',
TokenValidators = new Action<Token>[]
{
token => ValidateKeyword(token, "RUN"),
token => ValidateWhitespace(token, " "),
token => ValidateLineContinuation(token, '`', "\n"),
token => ValidateLineContinuation(token, '`', "\n"),
token => ValidateAggregate<ShellFormCommand>(token, "echo hello",
token => ValidateLiteral(token, "echo hello"))
}
},
new RunInstructionParseTestScenario
{
Text = "RUN echo `\n#test comment\nhello",
EscapeChar = '`',
Expand Down
14 changes: 14 additions & 0 deletions src/DockerfileModel/DockerfileModel.Tests/ShellFormCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,20 @@ public static IEnumerable<object[]> ParseTestInput()
}
},
new ShellFormCommandParseTestScenario
{
Text = "echo`\n `\n hello",
EscapeChar = '`',
TokenValidators = new Action<Token>[]
{
token => ValidateAggregate<LiteralToken>(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 = '`',
Expand Down
8 changes: 5 additions & 3 deletions src/DockerfileModel/DockerfileModel/ParseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,9 +308,11 @@ public static Parser<IEnumerable<Token>> LiteralString(char escapeChar, IEnumera
/// </summary>
/// <param name="escapeChar">Escape character.</param>
public static Parser<IEnumerable<Token>> ArgumentListAsLiteral(char escapeChar) =>
from literals in ArgTokens(
LiteralToken(escapeChar, Enumerable.Empty<char>()).AsEnumerable(),
escapeChar).Many()
from literals in
ArgTokens(
from literal in LiteralToken(escapeChar, Enumerable.Empty<char>()).Optional()
select new Token[] { literal.GetOrDefault() },
escapeChar).Many()
select CollapseLiteralTokens(literals.Flatten(), canContainVariables: false, escapeChar);

/// <summary>
Expand Down

0 comments on commit 35be2c4

Please sign in to comment.