ottobackwards commented on a change in pull request #3850: NIFI-6398 Added the
'replace first' and 'replace all' strategy to ReplaceText
URL: https://github.com/apache/nifi/pull/3850#discussion_r340660243
##########
File path:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/main/java/org/apache/nifi/processors/standard/ReplaceText.java
##########
@@ -673,6 +689,63 @@ public boolean isAllDataBufferedForEntireText() {
}
}
+ /**
+ * Replaces the first occurrence of a search value within a flow file with
the given replacement value. It can
+ * either be done line by line, meaning that the first occurrence within a
line gets replaced, or for the entire
+ * text, where only the very first occurrence is replaced.
+ */
+ private class ReplaceFirst implements ReplacementStrategyExecutor {
+ @Override
+ public FlowFile replace(FlowFile flowFile, ProcessSession session,
ProcessContext context, String evaluateMode,
+ Charset charset, int maxBufferSize) {
+ final String replacementValue =
context.getProperty(REPLACEMENT_VALUE)
+ .evaluateAttributeExpressions(flowFile).getValue();
+ final AttributeValueDecorator quotedAttributeDecorator =
Pattern::quote;
Review comment:
According to the java documentation, you should quote the replacement value
as well.
----------------------------------------------------------------
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]
With regards,
Apache Git Services