From f11c99f9ec2ed71d7ac017bd198d6bcd8248eb25 Mon Sep 17 00:00:00 2001 From: Peter Turcsanyi Date: Mon, 26 Apr 2021 19:07:52 +0200 Subject: [PATCH] NIFI-8475: Fixed EL query parser when input contains multiple escaped expressions Signed-off-by: Matthew Burgess This closes #5031 --- .../nifi/attribute/expression/language/Query.java | 1 + .../attribute/expression/language/TestQuery.java | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java index 5cbdf782b5..463ffe4474 100644 --- a/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java +++ b/nifi-commons/nifi-expression-language/src/main/java/org/apache/nifi/attribute/expression/language/Query.java @@ -336,6 +336,7 @@ public class Query { } addLiteralsAndParameters(parameterParser, treeText, expressions, true); + lastIndex = range.getEnd() + 1; } if (escapedRanges.isEmpty()) { diff --git a/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java b/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java index 7e1a71e1d4..1c38a9bc66 100644 --- a/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java +++ b/nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestQuery.java @@ -123,6 +123,18 @@ public class TestQuery { final PreparedQuery mixedQuery = Query.prepare("${foo}$${foo}"); final String mixedEvaluated = mixedQuery.evaluateExpressions(new StandardEvaluationContext(variables), null); assertEquals("bar${foo}", mixedEvaluated); + + final PreparedQuery multipleEscapedQuery = Query.prepare("$${foo}$${bar}"); + final String multipleEscapedEvaluated = multipleEscapedQuery.evaluateExpressions(new StandardEvaluationContext(variables), null); + assertEquals("${foo}${bar}", multipleEscapedEvaluated); + + final PreparedQuery multipleEscapedWithTextQuery = Query.prepare("foo$${foo}bar$${bar}"); + final String multipleEscapedWithTextEvaluated = multipleEscapedWithTextQuery.evaluateExpressions(new StandardEvaluationContext(variables), null); + assertEquals("foo${foo}bar${bar}", multipleEscapedWithTextEvaluated); + + final PreparedQuery multipleMixedQuery = Query.prepare("foo${foo}$${foo}bar${bar}$${bar}"); + final String multipleMixedEvaluated = multipleMixedQuery.evaluateExpressions(new StandardEvaluationContext(variables), null); + assertEquals("foobar${foo}bar${bar}", multipleMixedEvaluated); } private void assertValid(final String query) {