Github user ottobackwards commented on a diff in the pull request:
https://github.com/apache/nifi/pull/2748#discussion_r193371373
--- Diff:
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestReplaceText.java
---
@@ -81,15 +81,16 @@ public void testSimple() throws IOException {
@Test
public void testWithEscaped$InReplacement() throws IOException {
final TestRunner runner = getRunner();
- runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s:^.*$)");
+ //runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s:^.*$)");
+ runner.setProperty(ReplaceText.SEARCH_VALUE, "(?s)(^.*$)");
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "a\\$b");
runner.enqueue("a$a,b,c,d");
runner.run();
runner.assertAllFlowFilesTransferred(ReplaceText.REL_SUCCESS, 1);
final MockFlowFile out =
runner.getFlowFilesForRelationship(ReplaceText.REL_SUCCESS).get(0);
- out.assertContentEquals("a\\$b".getBytes("UTF-8"));
+ out.assertContentEquals("a$b".getBytes("UTF-8"));
--- End diff --
So, I think the behavior was incorrect before.
Since we do the Regex first now, and then the expression, what we end up
with is
a .replaceAll((?s)(^.*$)),"a\$b")
passing \$ to the regex evaluates as a literal '$', so the results it
correctly a$b.
In other words, it is working as the java regex works.
To get what you are looking for, further escaping is required:
```java
runner.setProperty(ReplaceText.REPLACEMENT_VALUE, "a\\\\\\$b");
```
I'll add the test
---