Skip to content

Commit

Permalink
[engine] Fix expressions resolution in multiline strings (#3511)
Browse files Browse the repository at this point in the history
  • Loading branch information
valfirst authored Jan 2, 2023
1 parent c712402 commit b147549
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ExpressionAdaptor implements DryRunAwareExecutor
private static final Pattern GREEDY_EXPRESSION_PATTERN = Pattern.compile("#\\{((?:(?!#\\{|\\$\\{).)*)}",
Pattern.DOTALL);
private static final Pattern RELUCTANT_EXPRESSION_PATTERN = Pattern.compile(
"#\\{((?:(?![#{]).[^(][^)])*?|(?:(?!#\\{|\\$\\{).)*?\\)|(?:(?!#\\{|\\$\\{).)*?)}",
"#\\{((?:(?![#{])[^)][^(][^)])*?|(?:(?!#\\{|\\$\\{).)*?\\)|(?:(?!#\\{|\\$\\{).)*?)}",
Pattern.DOTALL);

private static final String REPLACEMENT_PATTERN = "\\#\\{%s\\}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ class ExpressionAdapterTests

@ParameterizedTest
@CsvSource({
"'target', '#{target}', %s, " + EXPRESSION_RESULT,
"'target', '{#{target}}', {%s}, " + EXPRESSION_RESULT,
"'target', '{#{target} and #{target}}', {%1$s and %1$s}," + EXPRESSION_RESULT,
"'target(})', '#{target(})}', %s, " + EXPRESSION_RESULT,
"'tar\nget', '#{tar\nget}', %s, " + EXPRESSION_RESULT,
"'expr(value{1})', '#{expr(#{expr(#{expr(value{1})})})}', %s, value{1}"
"'target', '#{target}', %s, " + EXPRESSION_RESULT,
"'target', '{#{target}}', {%s}, " + EXPRESSION_RESULT,
"'target', '{#{target} and #{target}}', {%1$s and %1$s}," + EXPRESSION_RESULT,
"'target(})', '#{target(})}', %s, " + EXPRESSION_RESULT,
"'tar\nget', '#{tar\nget}', %s, " + EXPRESSION_RESULT,
"'expr(value{1})', '#{expr(#{expr(#{expr(value{1})})})}', %s, value{1}",
"'generateDate(-P19Y, yyyy)', '{#{generateDate(-P19Y, yyyy)}\n}', '{%s\n}', " + EXPRESSION_RESULT
})
void testSupportedExpression(String expressionKeyword, String input, String outputFormat, String outputValue)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,11 @@ Meta:
Given I initialize scenario variable `word` with value `"cowabunga"`
Given I initialize scenario variable `json` with value `{"question":"what is #{escapeJson(${word})}?"}`
Then `${json}` is equal to `{"question":"what is \"cowabunga\"?"}`

Scenario: Should evaluate expression in multiline string
Meta:
@issueId 3501
Given I initialize scenario variable `jsonWithYear` with value `{
"year": #{generateDate(-P19Y, yyyy)}
}`
Then `${jsonWithYear}` matches `\{\s+"year": 200\d\s+}`

0 comments on commit b147549

Please sign in to comment.