Skip to content

Commit

Permalink
Fix ENV inst parsing with newline (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthalman authored Nov 26, 2020
1 parent 8c17711 commit 67393f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
14 changes: 14 additions & 0 deletions src/DockerfileModel/DockerfileModel.Tests/EnvInstructionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,20 @@ public static IEnumerable<object[]> ParseTestInput()
}
},
new EnvInstructionParseTestScenario
{
Text = "ENV MY_NAME John\r\n",
TokenValidators = new Action<Token>[]
{
token => ValidateKeyword(token, "ENV"),
token => ValidateWhitespace(token, " "),
token => ValidateAggregate<KeyValueToken<IdentifierToken, LiteralToken>>(token, "MY_NAME John",
token => ValidateIdentifier(token, "MY_NAME"),
token => ValidateWhitespace(token, " "),
token => ValidateLiteral(token, "John")),
token => ValidateNewLine(token, "\r\n")
}
},
new EnvInstructionParseTestScenario
{
Text = "ENV MY_NAME=John",
TokenValidators = new Action<Token>[]
Expand Down
11 changes: 6 additions & 5 deletions src/DockerfileModel/DockerfileModel/EnvInstruction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ from literal in LiteralWithVariables(escapeChar, whitespaceMode: WhitespaceMode.
select literal.GetOrElse(new LiteralToken("", canContainVariables: true, escapeChar));

private static Parser<IEnumerable<Token>> SingleVariableFormat(char escapeChar) =>
KeyValueToken<IdentifierToken, LiteralToken>.GetParser(
IdentifierToken(VariableRefFirstLetterParser, VariableRefTailParser, escapeChar: escapeChar),
LiteralWithVariables(escapeChar),
separator: ' ',
escapeChar: escapeChar).AsEnumerable();
ArgTokens(
KeyValueToken<IdentifierToken, LiteralToken>.GetParser(
IdentifierToken(VariableRefFirstLetterParser, VariableRefTailParser, escapeChar: escapeChar),
LiteralWithVariables(escapeChar),
separator: ' ',
escapeChar: escapeChar).AsEnumerable(), escapeChar);
}
}

0 comments on commit 67393f0

Please sign in to comment.