turcsanyip commented on a change in pull request #4746:
URL: https://github.com/apache/nifi/pull/4746#discussion_r561153888
##########
File path:
nifi-commons/nifi-expression-language/src/test/java/org/apache/nifi/attribute/expression/language/TestStandardPreparedQuery.java
##########
@@ -309,6 +309,24 @@ public void testVariableImpacted() {
assertTrue(Query.prepare("${anyMatchingAttribute('a.*'):equals('hello')}").getVariableImpact().isImpacted("attr"));
}
+ @Test
+ public void testIsExpressionLanguagePresent() {
+ assertFalse(Query.prepare("value").isExpressionLanguagePresent());
+ assertFalse(Query.prepare("").isExpressionLanguagePresent());
+
+ assertTrue(Query.prepare("${variable}").isExpressionLanguagePresent());
+
assertTrue(Query.prepare("${hostname()}").isExpressionLanguagePresent());
+
assertTrue(Query.prepare("${hostname():equals('localhost')}").isExpressionLanguagePresent());
+
assertTrue(Query.prepare("prefix-${hostname()}").isExpressionLanguagePresent());
+
assertTrue(Query.prepare("${hostname()}-suffix").isExpressionLanguagePresent());
+
assertTrue(Query.prepare("${variable1}${hostname()}${variable2}").isExpressionLanguagePresent());
+
assertTrue(Query.prepare("${${variable}}").isExpressionLanguagePresent());
+
+ assertFalse(Query.prepare("${}").isExpressionLanguagePresent());
+
+ assertTrue(Query.prepare("#{param}").isExpressionLanguagePresent());
Review comment:
The parameter may or may not contain EL. My idea was to handle it as
"unknown" and I felt it safer to say `true` in this case.
I ran into this "isExpressionLanguagePresent always returns true" issue in
`customValidate()` and the parameter reference is already resolved when
`customValidate()` gets called. So only `StringLiteralExpression` (non-EL) and
`CompiledExpression` (EL) can occur there but no `ParameterExpression`. I was
uncertain about `ParameterExpression` because I do not know where else it is
being used in context of EL.
If you confirm that returning `false` is the right way I can easily change
the logic. I just wanted to explain what my approach was.
Thanks
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]