Skip to content

Commit

Permalink
Do not require comma delimiters for exec form (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
mthalman authored Oct 18, 2024
1 parent 5b8afd1 commit c031efe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
28 changes: 28 additions & 0 deletions src/Valleysoft.DockerfileModel.Tests/ExecFormCommandTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,34 @@ public static IEnumerable<object[]> ParseTestInput()
}
},
new ExecFormCommandParseTestScenario
{
Text = "[\"/bin/bash\" \"-c\" \"echo hello\"]\n",
TokenValidators = new Action<Token>[]
{
token => ValidateSymbol(token, '['),
token => ValidateLiteral(token, "/bin/bash", ParseHelper.DoubleQuote),
token => ValidateWhitespace(token, " "),
token => ValidateLiteral(token, "-c", ParseHelper.DoubleQuote),
token => ValidateWhitespace(token, " "),
token => ValidateLiteral(token, "echo hello", ParseHelper.DoubleQuote),
token => ValidateSymbol(token, ']'),
token => ValidateNewLine(token, "\n")
},
Validate = result =>
{
Assert.Equal(CommandType.ExecForm, result.CommandType);
Assert.Equal("[\"/bin/bash\" \"-c\" \"echo hello\"]\n", result.ToString());
Assert.Equal(
new string[]
{
"/bin/bash",
"-c",
"echo hello"
},
result.Values.ToArray());
}
},
new ExecFormCommandParseTestScenario
{
Text = "[ \"/bi`\nn/bash\", `\n \"-c\" , \"echo he`\"llo\"]",
EscapeChar = '`',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,22 @@ public static IEnumerable<object[]> ParseTestInput(string instructionName)
}
},
new FileTransferInstructionParseTestScenario
{
Text = $"{instructionName} [\"$src\" \"dst\"]",
TokenValidators = new Action<Token>[]
{
token => ValidateKeyword(token, instructionName),
token => ValidateWhitespace(token, " "),
token => ValidateSymbol(token, '['),
token => ValidateQuotableAggregate<LiteralToken>(token, "$src", ParseHelper.DoubleQuote,
token => ValidateAggregate<VariableRefToken>(token, "$src",
token => ValidateString(token, "src"))),
token => ValidateWhitespace(token, " "),
token => ValidateLiteral(token, "dst", ParseHelper.DoubleQuote),
token => ValidateSymbol(token, ']')
}
},
new FileTransferInstructionParseTestScenario
{
Text = $"{instructionName} [\"$src\", \"dst\"]\n",
TokenValidators = new Action<Token>[]
Expand Down
4 changes: 2 additions & 2 deletions src/Valleysoft.DockerfileModel/ParseHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -547,11 +547,11 @@ private static IEnumerable<Token> CollapseLiteralTokens(IEnumerable<Token> token
/// <param name="escapeChar">Escape character.</param>
private static Parser<IEnumerable<Token>> JsonArrayElementDelimiter(char escapeChar) =>
from leading in OptionalWhitespaceOrLineContinuation(escapeChar)
from comma in Symbol(',').AsEnumerable()
from comma in Symbol(',').AsEnumerable().Optional()
from trailing in OptionalWhitespaceOrLineContinuation(escapeChar)
select ConcatTokens(
leading,
comma,
comma.GetOrDefault(),
trailing);

/// <summary>
Expand Down

0 comments on commit c031efe

Please sign in to comment.