Github user markap14 commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2929#discussion_r210253136
--- Diff:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
---
@@ -701,6 +709,27 @@ private static String wrapLiterals(String
possibleLiteral) {
return replacementFinal;
}
+ /**
+ * Escapes Expression Language like text from content Strings.
+ * <p>
+ * Since we do regular expression replacement on the content and then
do Expression Language
+ * evaluations afterwards, it is possible that if there are Expression
Language like text
+ * in the content that they will be evaluated when they should not be.
+ * </p>
+ * <p>
+ * This function is called to escape any such construct by prefixing a
second $ to the ${...} text.
+ * </p>
+ *
+ * @param content the content that may contain Expression Language
like text
+ * @return A {@code String} with any Expression Language text escaped
with a $.
+ */
+ private static String escapeExpressionsInContent(String content) {
+ if (!content.contains("${")) {
+ return content;
+ }
+ return content.replaceAll("(\\$\\{.*\\})","\\$$1");
--- End diff --
I don't know if it's something that you can do in a regex or not... it
would be difficult... you'd need to find a ${, then count backwards the number
of $'s before it, and determine whether or not it's an even number. But again -
then, once escaped, you'd be evaluating Expression Language against it, and we
should not be evaluating the Expression Language against the content of the
FlowFile at all. This would all equate to quite a lot of heavy lifting for the
CPU. I do think that I have an alternate approach that would address both
NIFI-5474 and NIFI-4272. Will post a PR momentarily, and you can check that out
if you'd like.
---